Forum Discussion

retrotom's avatar
retrotom
Visitor
15 years ago

Orphan objects "error"

I've been noticing that the debugger sometimes says "Error! Found X orphaned objects". Does the relate to errors in our user code? And if so, is it possible to get more information so that we can clean it up better?

Thanks,
RT
  • As I understand it, "orphaned objects" are just circular references that the garbage collector wasn't able to clean up during execution. I don't think they're actual errors.
  • "RokuKevin" wrote:
    Endless, that is correct.

    --Kevin


    That makes sense, but I was wondering if there are any side affects because of that. If so, what (if anything) can we do about it? I don't know what a "high" number is for the number of objects that were orphaned -- but I consistently see a number above 2K. So (to me), that sounds like a lot of orphaned objects. I just want to make sure that we're not "leaking" all over the place. If we are, I'd like to be able to call something "GC.Collect()" and clean up when there's little/no user interaction.
  • "retrotom" wrote:

    That makes sense, but I was wondering if there are any side affects because of that. If so, what (if anything) can we do about it? I don't know what a "high" number is for the number of objects that were orphaned -- but I consistently see a number above 2K. So (to me), that sounds like a lot of orphaned objects. I just want to make sure that we're not "leaking" all over the place. If we are, I'd like to be able to call something "GC.Collect()" and clean up when there's little/no user interaction.


    It probably has more to do with the fact that the home button immediately kills the channel, and there's not a normal out of scope cleanup of variables. It probably considers everything as orphaned.

    I'm not positive, but I believe before they had the home button killing the channel automatically it didn't do that. It used to send a msg that could be caught. They changed the behavior so a misbehaving channel couldn't ignore home button presses.
  • "kbenson" wrote:

    It probably has more to do with the fact that the home button immediately kills the channel, and there's not a normal out of scope cleanup of variables. It probably considers everything as orphaned.
    I'm not positive, but I believe before they had the home button killing the channel automatically it didn't do that. It used to send a msg that could be caught. They changed the behavior so a misbehaving channel couldn't ignore home button presses.

    I don't think so. I get the same-ish number of "orphans" regardless of whether I use Home or I back out screen by screen. Many of my "classes" use callbacks to notify the screen/class that created them, so the child references the parent, hence the circular reference. I believe, when that screen closes, the garbage collector can't reconcile the circular reference definitively enough to know whether to clean it up or not, so it becomes orphaned. I do wonder if there are significant memory implications to that model and/or if there's a way to tell the system that it's safe to clean up.
  • "TheEndless" wrote:
    I believe, when that screen closes, the garbage collector can't reconcile the circular reference definitively enough to know whether to clean it up or not, so it becomes orphaned. I do wonder if there are significant memory implications to that model and/or if there's a way to tell the system that it's safe to clean up.


    That's my concern as well. I recall that on earlier firmware revisions that my channel would just crash for no reason sometimes. Sometimes it would freeze and I'd be unable to enter other channels or the channel store. I'd have to unplug power and restart it. I was wondering if it my be useful and/or possible to just have the framework/platform/roku run garbage collection whenever users hit the "main home" screen or something. Looking at the debugger -- the collection time is small enough to warrant such an action. Then again, with the newer firmwares...I'm seeing fewer stability issues -- so it might not be such a cause for concern.
  • If your app exits normally, the number of orphans should be zero. The garbage collector works by building a reference graph. The garbage collector may become fooled by objects that are referenced but not accessible by any start references in scope or global m. scope.

    So check your code for circular references....

    --Kevin