Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
boomAlex
Visitor

Memory problems

I am having major memory problems using the roScreen.

My app requires me to have many images loaded from the web and the device that are used frequently. This means I have to load them in to memory as a roBitmap, which uses a lot of memory. When I am done with the bitmaps I set them to invalid so that I can free up memory. However it seems that this does not clear up the memory right away. Is there some way that I can call the garbage collector through code? What memory management tools are there other then r2d2_bitmaps and running the garbage collector from the debug console?

I have to get this figured out because i can't just have my app randomly crash because the Roku is out of memory.
0 Kudos
5 REPLIES 5
TheEndless
Channel Surfer

Re: Memory problems

You can run the garbage collector from code by calling RunGarbageCollector(). That does not, however, in my experience, free up graphics memory. How are you creating your roBitmaps? They will only be unloaded from memory, if you remove all references to them, so setting the original bitmap to invalid will only work if you haven't referenced that bitmap from any other object in your code. If you're not already, you may want to consider using the roTextureManager to manage your bitmaps, as it does a lot of the caching, loading and unloading legwork for you.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
boomAlex
Visitor

Re: Memory problems

RunGarbageCollector() not freeing up graphics memory is rather annoying, I am de-allocating and re-allocating memory rather quickly in some cases so I was hoping to force the garbage collector to run in between the de-allocating and re-allocating to prevent crashing. roTextureManager looks really promising so I will be implementing that, Hopefully that will be enough to stop the app from crashing from running out of memory.

Thanks!
0 Kudos
squirreltown
Roku Guru

Re: Memory problems

"boomAlex" wrote:
RunGarbageCollector() not freeing up graphics memory is rather annoying, I am de-allocating and re-allocating memory rather quickly in some cases so I was hoping to force the garbage collector to run in between the de-allocating and re-allocating to prevent crashing.


You also need to leave some headroom. For a 2XS with 39mb of graphics memory I would never go over 35mb used for any reason and preferably less than that. R2D2 is your only friend with this.
Kinetics Screensavers
0 Kudos
boomAlex
Visitor

Re: Memory problems

35mb is going to be a real challenge!

I don't know if I will be able to keep it that low. Thanks for the info though I was wondering what the lowest memory a Roku had was.
0 Kudos
RokuJoel
Binge Watcher

Re: Memory problems

Generally to free up graphics memory:

Release any variables referencing the bitmaps, i.e. regions and sprites:

sprite.remove()
spriteregion=invalid
bitmap=invalid


then call SwapBuffers() or finish() if the screen is single buffered. That should free up the unloaded texture. If you are using he TextureManager, then you might also need to unload the bitmap from texture manager:

MyTexMgr.UnloadBitmap("http://myserver.com/mybitmaps/image.jpg")

- Joel
0 Kudos