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: 
olarurazvan
Visitor

Re: calling Remove on a sprite

You're right. That slipped away. But still, why after removing the sprite the memory gets depleted? Do I also have to delete the entry from the sprites array (spritesArray.delete(spriteIndex))?
0 Kudos
NewManLiving
Visitor

Re: calling Remove on a sprite

If you look at the code above, your arrays persist for the entire application since they are defined in main. The regions that you push on to the array hold a reference to their bitmap. This means the bitmaps created there also persist ( continue to be referenced ). You would need to set those top-level references to invalid to get rid of the bitmap in memory. You should use a telnet session at your device IP, port 8080. Issue the command r2d2_bitmaps (ignore the initial command not found message and reissue the command) this shows all the bitmaps in memory and how much memory is being used. This way you can be sure you have gotten rid of all references
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
NewManLiving
Visitor

Re: calling Remove on a sprite

And by the way, the sprite = Invalid is also just another reference passed into the function. You are only setting the argument sprite to invalid. So you need to review and understand how references work.
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos

Re: calling Remove on a sprite

"NewManLiving" wrote:
If you look at the code above, your arrays persist for the entire application since they are defined in main. The regions that you push on to the array hold a reference to their bitmap. This means the bitmaps created there also persist ( continue to be referenced )


I only store the sprites in a global array. The bitmap and region used for creating a sprite are local variables of a function so they should be "garbage collected" after exiting the function (exits after drawing a new item on screen). Only the six visible sprites should be held in memory and the others should have invalid value. To better understand, I call something like m.globals.spriteArray[spriteIndex].remove() and m.globals.spriteArray[spriteIndex] = invalid with each list scroll for the first sprite to be deleted and create a new roSprite for the last item that will become visible. There are only six items in the array that are of type "roSprite" and the rest are invalid at each given time. The problem is that after scrolling about 400 items the memory still gets depleted.

"NewManLiving" wrote:
And by the way, the sprite = Invalid is also just another reference passed into the function. You are only setting the argument sprite to invalid. So you need to review and understand how references work.


Sorry for the confusion with references. I did that by mistake, beeing to desperate to free memory :)). I get how references work in Roku.
0 Kudos
NewManLiving
Visitor

Re: calling Remove on a sprite

It's best to post all your current code. Apparently it has changed from your beginning post.
Looking at everything it will be easier to tell where there is a reference leak
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
NewManLiving
Visitor

Re: calling Remove on a sprite

When dealing with the 2d it's best to get a telnet like puttytel set it up like I said and view it as you scroll to see how bitmaps are released
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
olarurazvan
Visitor

Re: calling Remove on a sprite

"NewManLiving" wrote:

It's best to post all your current code. Apparently it has changed from your beginning post.
Looking at everything it will be easier to tell where there is a reference leak.


NewManLiving, I am different guy from the one that started the tread. The problem is that the code is huge about 1200 lines of code only for the part with the list (it's a vast MVC structured app) and that's why I've explained briefly what i have done. If you consider what I have written so far too confusing then don't bother too much because, anyway, I greatly appreaciate that you took some your time to help.
0 Kudos
NewManLiving
Visitor

Re: calling Remove on a sprite

It's not a matter of confusion. There is nothing confusing about it. Looking at the code you/someone initially submitted along with the function that removes the sprites shows a number of errors related to references even if they were out of "desperation". I was curious if you had changed the code somewhat since then. Your problem still suggests a reference leak. Requesting the code was just to examine what you had changed not because I thought it was confusing. My own libraries contain thousands of lines of code. I hope you find your problem
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos