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: 
GandK-Geoff
Visitor

Garbage collection of bitmaps

Is there any way to force roBitmaps to be garbage collected immediately, rather than waiting for channel exit?

I'm working on something that will be using vast tracts of video memory, but not all at once. I believe I can fit my needs for any given moment within the available RAM, but I need to be able to immediately evict old bitmaps so that I can load/create new ones. Unfortunately, if there is a way to do this, I have not yet found it.

The alternative of course is to create several large texture atlases at startup, and manually page my textures in and out of them. Unfortunately that means complexifying a fair chunk of BrightScript -- not so much "hard" as "slow to code, slow to debug, and slow to execute". 😕

So ... any idea how to fully garbage collect video memory? I can probably manage my bitmap usage well enough to choose the right time to absorb a small pause (<1 second, smaller is better of course) without the user being the wiser, so a "stop the world" collection is not the worst thing ever if that's what it comes to.
0 Kudos
5 REPLIES 5
TheEndless
Channel Surfer

Re: Garbage collection of bitmaps

I haven't used it, but there's a new RunGarbageCollector() function. Perhaps invalidating the bitmap and calling that would accomplish what you're looking for?
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
GandK-Geoff
Visitor

Re: Garbage collection of bitmaps

"TheEndless" wrote:
I haven't used it, but there's a new RunGarbageCollector() function. Perhaps invalidating the bitmap and calling that would accomplish what you're looking for?


Second thing I tried. No dice. 😞
0 Kudos
GandK-Geoff
Visitor

Re: Garbage collection of bitmaps

ARGGH. So this isn't a real problem after all -- bitmap garbage collection seems to be working.

The problem with my code is that at some point after the first run of loading up video memory, an apparently innocent calculation changed the type of one of my size variables. Then when I used this to set the size of the next bitmap to be created, it silently failed.

Silent failure is bad, so I'm starting a separate thread with a bug report.
0 Kudos

Re: Garbage collection of bitmaps

Setting an element to invalid explicitly should work.

bmp = CreateObject("roBitmap", "pkg:/file.jpg")
bmp = invalid

This reduces the reference count to zero and frees the object.

If you're seeing a problem try running the RunGargageCollector() as Endless suggested.

Does anyone know of a good memory visualization method for BrightScript? I'd like to be able to run something that would allow me to inspect the available memory, the used memory, and preferably a list of the objects with their reference counts and used memory. Just the first two would be enough for me to execute periodically and print to ensure I'm not eating away at memory with a poorly executed loop.
0 Kudos
kbenson
Visitor

Re: Garbage collection of bitmaps

"RyanMarquiste" wrote:

Does anyone know of a good memory visualization method for BrightScript? I'd like to be able to run something that would allow me to inspect the available memory, the used memory, and preferably a list of the objects with their reference counts and used memory. Just the first two would be enough for me to execute periodically and print to ensure I'm not eating away at memory with a poorly executed loop.


I think the best you'll get is the debugger. It's inconvenient, but I believe it provides most of what you are looking for (in an execution halting case).
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos