android
  #1  
Old 03-01-2011, 12:03 PM
Redwolfhome's Avatar
Redwolfhome Redwolfhome is offline
Junior Member
 
Join Date: Mar 2010
Location: Germany
Posts: 91
Default A new and better way to save memory

I think some of you (Zen X-Fi II developers) know this problem. We want to save memory because the zen doesnt have enough!
So maby we create a second load which close the first loaded images and load new ones. But in our Pingus game we have the problem that there also was not enough memory.
So i have try a few ways and was successful. I have found a function which gives you the currentyl used memory. It is called gcinfo() and so you can get the currently used memory like this way:
Code:
print(gcinfo());
So i have try to open a image and close it and my result was that the zen doesnt delete the memory which was used before. But then I have found another function it is called collectgarbage()! This function delete all the unused cache and garbage and after a few tests I can say that the function is very useful.
So just close all images and then just put at the end collectgarbage()!
And I have asked myself why is there a function which is called screen.clear() and nobody used this function? So i have test this function and it also doesnt happend anythink. But after i run the garbage collector there was a little bit more memory free

So my result is that you have to close a image with
Code:
exampleimage:close();
collectgarbage()
or with:
Code:
exampleimage = nil;
collectgarbage()
but this way doesnt get another effect:
Code:
exampleimage:close();
exampleimage = nil;
collectgarbage()
Try it yourself and you will be lucky with the new way to save memory
And another really good think is that you can close all images and put this at the end of your file:
Code:
screen.clear();
collectgarbage()
And so all garbage will be deleted


Redwolfhome
Reply With Quote

Advertisement [Remove Advertisement]

  #2  
Old 03-01-2011, 02:08 PM
İreative's Avatar
İreative İreative is offline
Junior Member
 
Join Date: Jun 2010
Location: Minnesota, USA
Posts: 39
Default

Great work! Just a few questions:
Do we know what unit gcinfo() reports in? Kb?
What is the maximum memory alloted for our app's use?
Also, I didn't quite understand what screen.clear() does. Just free up a little more memory?
Reply With Quote

  #3  
Old 03-01-2011, 02:46 PM
Nohajc's Avatar
Nohajc Nohajc is offline
Junior Member
 
Join Date: Mar 2010
Location: Czech Republic
Posts: 68
Default

Nice findings. I'll add the final two lines into my code immediately.
__________________
There was a little man...
Reply With Quote

  #4  
Old 03-05-2011, 03:20 AM
Redwolfhome's Avatar
Redwolfhome Redwolfhome is offline
Junior Member
 
Join Date: Mar 2010
Location: Germany
Posts: 91
Default

Quote:
Originally Posted by İreative View Post
Great work! Just a few questions:
Do we know what unit gcinfo() reports in? Kb?
What is the maximum memory alloted for our app's use?
Yes the reports are in KB

Quote:
Originally Posted by İreative View Post
Also, I didn't quite understand what screen.clear() does. Just free up a little more memory?
Ok i Want to descripe it if you draw for example a black background about the hole screen and then you draw a second background which just take a few pixels you can see that the old background is still there - So if you draw something on the screen it just overlays the old screen.
And I think screen.clear just delete the trash of this process.

Quote:
Originally Posted by İreative View Post
What is the maximum memory alloted for our app's use?
I dont know
Reply With Quote

  #5  
Old 03-05-2011, 06:25 AM
Brett_val's Avatar
Brett_val Brett_val is offline
Senior Member
 
Join Date: Jan 2010
Location: The Netherlands
Posts: 636
Default

Nice one, I thought lua did automatic garbage collection, but good to know that it does make a difference using it.
__________________
this is a link to my personal homepage which I haven't
Reply With Quote

  #6  
Old 03-05-2011, 07:09 AM
Android18 Android18 is offline
Junior Member
 
Join Date: Dec 2010
Location: Pokhara,Nepal
Posts: 35
Default

collectgarbage if used removes about more than 100 bytes as soon as the app runs


And do we have a function to know the current processes.

may be collectgarbage has replaced gcinfo()
Reply With Quote

  #7  
Old 03-09-2011, 06:47 AM
Android18 Android18 is offline
Junior Member
 
Join Date: Dec 2010
Location: Pokhara,Nepal
Posts: 35
Default

--limit 550000 bytes approx
Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 12:31 PM.