GandK-Geoff
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2011
11:12 AM
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.
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.
5 REPLIES 5

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2011
11:29 AM
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
GandK-Geoff
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2011
11:43 AM
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. 😞
GandK-Geoff
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2011
01:18 PM
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.
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.
RyanMarquiste
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2011
05:17 PM
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.
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.
kbenson
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2011
09:34 PM
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!
Check out Reversi! in the channel store!