Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
kyleabaker
Level 7

View available memory in debug console?

I have an channel that plays video files from a usb device. It is working great most of the time, however, the video playback freezes and the Roku 3 restarts. I've not been able to find a case that consistently reproduces the crash, but I would like to log out memory usage if thats possible to monitor the debug console while using the channel so I can rule out a memory leak... or hopefully pin-point the leak.

Also, what is the best way to free memory or free up a variable that is no longer needed?
0 Kudos
3 Replies
Roku Employee
Roku Employee

Re: View available memory in debug console?

You can call runGarbageCollector() to free up memory from released variables at any time, normal garbage collection runs on a periodic basis. If it is video memory, releasing all sprites, regions and bitmaps and then calling screen.finish() or screen.swapbuffers() should release that memory. Depending on the model of Roku you are using, SetMaxVideoDecodeResolution may help if you are using roVideoPlayer

If you are storing anything in tmp:/ that isn't being used you could delete that as well.

- Joel
0 Kudos
MattBates
Level 7

Re: View available memory in debug console?

"kyleabaker" wrote:
...I would like to log out memory usage if thats possible to monitor the debug console while using the channel so I can rule out a memory leak... or hopefully pin-point the leak.


The only way I've found to indirectly look at memory usage is by running garbage collection in the debug console to see a total number of brightscript component instances

http://sdkdocs.roku.com/display/sdkdoc/Brightscript+Debug+Console

You can send a cancel signal to the debugger (Ctrl+C) to halt execution,
then execute 'gc' to run the garbage collector which outputs the number of 'bscs' aka brightscript components.

This isn't the best solution, but it gives you some idea of your memory usage and you will be able to monitor if this number gets out of hand.

For more detail on the components themselves, you can run 'bsc'.

Hope this helps, let us know if you find a better solution!
0 Kudos
EnTerr
Level 8

Re: View available memory in debug console?

"MattBates" wrote:
let us know if you find a better solution!

Well, you can use the globaly pre-defined function RunGarbageCollector() in your code. It's marginally better in that it does the same like console "gc" but there is no need to interrupt the program, it can just check and e.g. print periodically RunGarbageCollector().count . Doc on it shows great example on how orphans are created btw, kudos.
0 Kudos