user just kills the app (How to handle memory)

If Normal apps do not quit, the user just switches app or kills the app and we can’t use os.exit() then how do I handle memory created for the entire life of my game –

In composer, I can delete memory  between scenes BUT coz I won’t know when the app is forced to quit. What about  memory I created in the main.lua file that’s not display objects. i.e.  

main.lua


local composer = require( “composer” )

_G.TextCandy = require(“lib_text_candy”)
_G.Particles = require(“lib_particle_candy”)
_G.GUI = require(“widget_candy”)

TextCandy.AddCharset (“GAME_FONT”, “Celtic_Big_Rock”, “Celtic_Big_Rock.png”,
“0123456789AaBCDEFGHIJKLMNOoPQRSTUuVWXYZ’*@():,$.!-%+?;#/_”, 24)
<-------------------WHEN WOULD I DELETE THIS CHARSET??

require( “ParticleTypes” )<------WHEN WOULD I DELETE THESE PARTICLE
TYPES??

composer.isDebug = true
composer.loadScene(“menu”)

timer.performWithDelay( 550,function()   
       composer.gotoScene(“menu”,“crossFade”, 500)       
 end )


Would I just NOT WORRY about that memory??

Anyway, thanks for any help. Much appreciated.

Jeff

@Jeff,

  • ’required’ modules - Once a module is required, it is in memory and will be to the end of the game.  requiring it again will return a reference to the same module (if one was returned in the first place).  It won’t grow because of additional calls to require.  You can find scripts out there for unrequire(), but it’s not a great practice and can be unsafe if you don’t know the side-effects.
  • Text Candy - I’m not familiar with the internals of ‘Text Candy’, but my guess is the operation you just outlined is not very costly and probably a one time deal like require().
  • Composer - Be sure to add all groups and objects created in a scene into the scenes’s group ( self.view in standard scene method).  Then, when the scene is removed, composer will clean it all up for you.  Just don’t leave file-level or global references to objects laying around.

The moral of the story, when it comes to memory and performance optimization, is “do not do it unless you find you need to.”

If you do suspect you have a problem, tools for measuring memory and FPS do exist.  As well, here is a great profilerto find code hot spots.

Cheers,

Ed

PS - You can also  have your app exit on suspend if you want:

https://docs.coronalabs.com/guide/distribution/buildSettings/index.html#TOC

build.settings

settings = { iphone = { plist = { UIApplicationExitsOnSuspend = true, }, }, }

If your app is force quit, then you come back fresh when the app is loaded. 

Thanks roaminggamer & Rob. It really helps :slight_smile:

@Jeff,

  • ’required’ modules - Once a module is required, it is in memory and will be to the end of the game.  requiring it again will return a reference to the same module (if one was returned in the first place).  It won’t grow because of additional calls to require.  You can find scripts out there for unrequire(), but it’s not a great practice and can be unsafe if you don’t know the side-effects.
  • Text Candy - I’m not familiar with the internals of ‘Text Candy’, but my guess is the operation you just outlined is not very costly and probably a one time deal like require().
  • Composer - Be sure to add all groups and objects created in a scene into the scenes’s group ( self.view in standard scene method).  Then, when the scene is removed, composer will clean it all up for you.  Just don’t leave file-level or global references to objects laying around.

The moral of the story, when it comes to memory and performance optimization, is “do not do it unless you find you need to.”

If you do suspect you have a problem, tools for measuring memory and FPS do exist.  As well, here is a great profilerto find code hot spots.

Cheers,

Ed

PS - You can also  have your app exit on suspend if you want:

https://docs.coronalabs.com/guide/distribution/buildSettings/index.html#TOC

build.settings

settings = { iphone = { plist = { UIApplicationExitsOnSuspend = true, }, }, }

If your app is force quit, then you come back fresh when the app is loaded. 

Thanks roaminggamer & Rob. It really helps :slight_smile: