Cleaning up text resources (BList or BListPlus)

Discussion in 'Developers Corner' started by iolsen, Aug 18, 2009.

  1. iolsen

    iolsen Harmonium Maintainer

    45
    0
    Aug 18, 2009

    Advertisements

    My app occasionally crashes on the Tivo with the dreaded out of memory error. I believe this is a Tivo resource issue, not a Java heap error. (The java process on my PC keeps running and isn't anywhere nead its max heap size. I can't make the simulator crash under any circumstances; only the Tivo.)

    I'm 95% sure at this point, by watching the resources window in the simulator, text resources are to blame. But I'm having trouble freeing them. Most of the text resources get created by bananas BLists. I've also tried playing with bananas-plus and BListPlus. But I'm missing something, because I can't get the simulator to indicate that text resources have been removed.

    In BList's createRow(), I create a BText instance. If I save references to these, and later call BText.remove(), should I expect the simulator to decrement the number of text resources? It doesn't. (Image resources, on the other hand, seem to behave predictably in this way.) Am I doing something dumb? Is there something unique about Text resources inside a BList?

    Hopefully people still read this forum occasionally. :)

    Thanks for your time!
    Ian
     
  2. apps-tv

    apps-tv apps.tv for hme apps

    66
    0
    Sep 8, 2005
    San Jose, CA
    This is a bug in bananas, The shadow text resource doesn't get freed.
     
  3. iolsen

    iolsen Harmonium Maintainer

    45
    0
    Aug 18, 2009
    Thanks for the response.

    Reading the source for BList, it doesn't look like there's any attempt to clean up anything, which matches what I see in the resource window. It's not like some of the text resources go away. None of them do. :)

    And since you can do whatever you want in the createRow method, it doesn't really seem like it's BList's job to clean things up.

    Either way, armed with the bananas source, it seems like I ought to be able to fix this if I knew what I was doing. :)

    The obvious things haven't worked. If I remove the row text resources in the screen's handleExit, the app crashes. Is the screen trying to access them after handleExit runs?

    BListPlus (from bananas plus) seems to have made some effort to make it easier to clean up after yourself. I see a disposeRow method, but I can't figure out how it gets called. My derived method never does. Has anybody else done something like this? I can't be the only one using BList (or BListPlus) with large lists.
     
  4. iolsen

    iolsen Harmonium Maintainer

    45
    0
    Aug 18, 2009
    Okay I figured this out. There were two things I didn't understand:

    1) You have to walk the view tree to totally clean things up. Removing a BText's resource (via something like BText.getResource().remove()) doesn't cut it. It's helpful to have a recursive routine like this around:

    Code:
    static protected void cleanup(View v) {
    	int childCount = v.getChildCount();
    	for (int i = 0; i < childCount; i++) {
    		View child = v.getChild(i);
    		cleanup(child);
    	}
    	Resource r = v.getResource();
    	if (r != null)
    		r.remove();
    }
    calling this on a BText will truly remove cleanup all the relevant resources.

    2) You can't clean up a BScreen or its resources in its handleExit routine. Thanks to s2kdave in this thread for putting me on the right track there. His suggestion is a nice clean solution.
     

Share This Page

spam firewall

Advertisements