Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
joetesta
Level 10

any way to find orphaned objects?

Greetings,

I'm stuck on an issue and hoping for some help.
When our app launches, it makes an API call and gets data (currently playing programs). At this point hitting home button shows about 30K orphaned objects.

Now I'm trying to add a feature that allows the user to view more data (future scheduled programs) by making additional API calls. After a point, the roku freezes and reboots.
I assumed it was due to too much data stored in memory, so I'm testing this same feature by trying not to store any of the data; just making the API calls and it's still freezing and rebooting after 10 + API calls.
I'm trying to figure out why, and when exiting the app after a few such API calls, there are > 300K orphaned objects.
I've been tracing through the code and looking for anything that might be storing the data and building up these orphans but having no success.
Is there any way to see where these orphans are being stored? Are they necessarily in the global (m) array?

thanks in advance for any help with this,
Joe
aspiring
0 Kudos
15 Replies
EnTerr
Level 8

Re: any way to find orphaned objects?

If objects are pointed by the GetGlobalAA(), they won't be considered orphans. Usually orphans are created by releasing cyclic structures - they don't get freed outright by the reference counter, only on GC call. I don't know what be causing you leaking, perhaps you should share more details.

You can break into your code - STOP or ctrl-C in console - and explore what's going on. Try var, up, down, bsc, help. Keep us posted?
0 Kudos
joetesta
Level 10

Re: any way to find orphaned objects?

Thanks for your help EnTerr!

I'm trying as you suggested, after stop, when i enter 'bsc' a ton of stuff scrolls by, all sorts of things: roAssociativeArrays, roStrings, roInts, roVideoPlayerEvents
but what does this tell me; can i find what's referencing and clear up all this stuff?

BrightScript Debugger> bsc
roGlobal refcnt= 1
roIntrinsicDouble refcnt= 2
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 2
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 2
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roAssociativeArray refcnt= 2
roString refcnt= 1 [foreground]
roString refcnt= 1 [EXIT_UNKNOWN]
roString refcnt= 1 [homescreen]
roString refcnt= 1 [3000]
roAssociativeArray refcnt= 5
roAssociativeArray refcnt=24
. etc...


here is the summary;
BrightScript Debugger> bscs
roArray: 8094
roAssociativeArray: 17617
roBitmap: 54
roBoolean: 12
roByteArray: 1
roCaptionRenderer: 1
roCaptionRendererEvent: 57
roCompositor: 1
roDateTime: 2573
roDeviceInfo: 5
roFilesystem: 1
roFont: 8
roFontRegistry: 1
roFunction: 20
roGlobal: 1
roInt: 232
roIntrinsicDouble: 107
roList: 1
roMessagePort: 1
roRegion: 51
roScreen: 1
roSprite: 57
roString: 64806
roTextureManager: 1
roTimespan: 19
roUrlTransfer: 5
roVideoPlayer: 1
roVideoPlayerEvent: 139
Total # components: 93867
aspiring
0 Kudos
EnTerr
Level 8

Re: any way to find orphaned objects?

Using "var" while walking the call stack with "up"/"down" should help further.

What does RunGarbageCollector() say?
BrightScript Debugger> ? RunGarbageCollector()
COUNT: 1396
ORPHANED: 0
ROOT: 90
0 Kudos
joetesta
Level 10

Re: any way to find orphaned objects?

BrightScript Debugger> ? RunGarbageCollector()
COUNT: 88541
ORPHANED: 0
ROOT: 751
aspiring
0 Kudos
EnTerr
Level 8

Re: any way to find orphaned objects?

No orphaned objects reported by GC in console, huh?

Hard to diagnose remotely but i'll take a shot: my guess is you are setting some giant structure in a global variable (field in global "m" / GetGlobalAA()) and what you see reported on app exit are not real orphans but due to cleanup of globals. If it bothers you, just set your global vars to `invalid` before exiting.
0 Kudos
joetesta
Level 10

Re: any way to find orphaned objects?

someone mentioned cyclical references on another thread, is this what I should be on the lookout for?
app = app.myfun.app = app.myfun.app.myfun.app

the number doesn't bother me, it's the fact that the roku locks up and reboots after making 10 or 20 API calls. and the amounts shown w bscs are about 10X what i would've expected, there must be something going on here. I'll keep at it.

Thanks for your help getting this far Smiley Happy
aspiring
0 Kudos
EnTerr
Level 8

Re: any way to find orphaned objects?

DIY orphanage:
BrightScript Debugger> malkovich = { }: malkovich.malkovich = malkovich

BrightScript Debugger> gc
total number of current bscs: 1398
number of root bscs: 92
number of orphaned bscs: 0

BrightScript Debugger> malkovich = invalid

BrightScript Debugger> gc
total number of current bscs: 1398
number of root bscs: 91
number of orphaned bscs: 1

BrightScript Debugger> malkovich = [ ]: malkovich.push(malkovich): malkovich = invalid

BrightScript Debugger> gc
total number of current bscs: 1398
number of root bscs: 91
number of orphaned bscs: 1

Yes... if it was indeed because of orphans that it's running out of memory and crashing. But i doubt that very much.
That orphans are involved, that is. That it crashes because of low memory - i believe very much.
Unfortunately there is no way to see how much memory your app is using. Or how much is free. Because... Roku.

BrightScript Debugger> dim restart[1e9]     'YAWRR,  http://forums.roku.com/viewtopic.php?f=34&t=73863
Connection closed by foreign host.
0 Kudos
joetesta
Level 10

Re: any way to find orphaned objects?

thanks - I've been trying to set everything = invalid in the debugger, going up / down and using var, but even after setting everything I can see to invalid it brought the GC count from 67k down to about 64k
BrightScript Debugger> ? runGarbageCollector()
COUNT: 64558
ORPHANED: 0
ROOT: 29

the data stored shouldn't be that big, and should be overwritten on subsequent API calls, which I assume shouldn't increase the count / memory usage... need to keep digging. thanks,
aspiring
0 Kudos
Roku Employee
Roku Employee

Re: any way to find orphaned objects?

"joetesta" wrote:
Thanks for your help EnTerr!

I'm trying as you suggested, after stop, when i enter 'bsc' a ton of stuff scrolls by, all sorts of things: roAssociativeArrays, roStrings, roInts, roVideoPlayerEvents
but what does this tell me; can i find what's referencing and clear up all this stuff?

BrightScript Debugger> bsc
roGlobal refcnt= 1
roIntrinsicDouble refcnt= 2
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 2
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 2
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roIntrinsicDouble refcnt= 1
roAssociativeArray refcnt= 2
roString refcnt= 1 [foreground]
roString refcnt= 1 [EXIT_UNKNOWN]
roString refcnt= 1 [homescreen]
roString refcnt= 1 [3000]
roAssociativeArray refcnt= 5
roAssociativeArray refcnt=24
. etc...


here is the summary;
BrightScript Debugger> bscs
roArray: 8094
roAssociativeArray: 17617
roBitmap: 54
roBoolean: 12
roByteArray: 1
roCaptionRenderer: 1
roCaptionRendererEvent: 57
roCompositor: 1
roDateTime: 2573
roDeviceInfo: 5
roFilesystem: 1
roFont: 8
roFontRegistry: 1
roFunction: 20
roGlobal: 1
roInt: 232
roIntrinsicDouble: 107
roList: 1
roMessagePort: 1
roRegion: 51
roScreen: 1
roSprite: 57
roString: 64806
roTextureManager: 1
roTimespan: 19
roUrlTransfer: 5
roVideoPlayer: 1
roVideoPlayerEvent: 139
Total # components: 93867


Having a bunch of event objects (roCaptionRendererEvent and roVideoPlayerEvent) seems unusual to me.
Are you storing references to those events when your receive them?

Also, 2573 roDateTime seems extreme.
Perhaps you could track through the creation and storage of some of those objects, to see if they are being references from some global data structure unnecessarily?
0 Kudos