Difference in system memory usage on device and simulator?

I have my system memory usage on the simulator drop to normal values with a scene change. I can start the level scene, go back to the main menu, start level again, go back and the values stay the same.

Now I have tested this on my device (iPhone 6) and noticed the system memory is increasing with every time I’m calling the level scene about 400 KB.

I now wonder what can cause this because it only happens on device?

Any help and suggestions where I can look at welcome!

hi,

my two cents on the subject.

you have established that using the simulator, memory seem to clean up each time, so all seem to be in order. that is good practice and an indication if something is seriously wrong or not. i do the same myself.

however, the simulator runs on a pc or a mac with practically unlimited power and cpu resources, unlike typical devices and their operating systems, which are more tuned for low battery usage, temporary suspension, smoother user experience and so on.

most likely its a os cache and the device will clean it if/when needed.

as long as all works fine, dont worry about it.

Thanks for your fast reply. I now have tested it longer on device to see how much it will add up to…

and right now I’m at 82+ MB system memory usage which is way to high!

I noticed something else strange: around 64MB usage the level animations started to lag and get slow. Moving parts which normally had smooth transitions, stopped a very short time, started to move again a while, then stopped again and so on. Things look to get slower each time I restart the level.

Any idea on this?

that is strange but I still dont know if the memory usage is a problem in itself, however the lagging and slowdown can be an indication that something is happening in the background that isnt good. i’d check that all my objects, sounds, displaygroups and what not are dispatched of properly.

yet, any error/behaviour should show up in the simulator as well so the question is, what do you do programmatically that the simulator is fine with but ios not? do you see the same behaviour on devices running android?

i dont usually develop for ios, so someone with more hands on experience on ios device is needed here.

I still have to run tests for Android.

Is it possible a scene can get called twice maybe? So it loads “doubled”? Then maybe not everything gets removed correctly what was created in this scene. Is such a scenario even possible?

I’m asking because early in development I had a strange bug, where my level code (scene DID phase when everything was on screen) was run twice! I did remove this by adding a check variable but couldn’t find a problem by calling this scene.

Just an idea where I’m starting to look at right now because maybe the scene (composer) handling is different on the simulator and device!?

that something is loading twice, then being removed once, is a good theory for this type of behaviour, and a good place to start.

i dont use scenes, so not very familiar with their inner works.

live game hunting is like amateur hour compared to the sometimes daunting task code bug hunters are challenged with  :smiley:

So it looks it is not the scene call or I did miss something. I have tested all the scene changes with print outputs and everything worked fine.

One other thing could be the admob features which are not supported in the simulator but on device.

Is there something which comes to mind regarding admob maybe? But even if there is a global function or something, this doesn’t explain the size of this strange leak. It’s near 500KB of additonal system memory used everytime I restart the scene.

I now have changed my sound code, so the sounds are loaded only once in main.lua … so this also can’t be the problem.

Graphics should be visible in the texture memory too, right?

So what is left to look at which is handled differently on device compared to the simulator on a Mac?

i dont use ads but i dont think admod would make a mistake, but there is one way to find out. disable it in your app and try and see what happens.

graphics are visible yes.

unless someone else here can specifically give you a ios related hint, i think you are stuck with disabling all parts one by one until you  figure out the culprit, or vice versa, disable all, then enable each part and/or screen step by step, until you figure this out.

sorry i cant be of more help on this

come to think of it, admob only runs on device and not in the simulator, so I’d start there!

I was going to go there. There are things that run on the device that don’t in the simulator from camera/photo album operations, to microphone usage to plugins.

Plugins would be a great place to start looking.

Rob

Thanks for the tip Rob.

The only thing I am using is Dusk which is different to the other scenes (which are working fine btw). Just the level scene is making this problem. There I have Dusk and Physics in use.

I will start looking into this two.

I wonder if the admob plugin features can cause this behavior?

I am requiring the plugin in main.lua and then use it globally (also the listener).

I load and display the ads in my level scene file where I have the problems with the 500KB adding up to the system memory.

When doing: admob.load(…) and then admob.show when it has loaded… is this maybe is adding up to memory because I am using admob globally?

UPDATE: I now changed the admob plugin usage and requiring to just empty functions to test it. Something like this:

admob={}

admob.init=function() end

And I still have the same problem on device.

One more question I have:

When I change the scene on and off and on until I get to about 64 MB of system memory usage on device things start to lag and get slow. Isn’t this a sign some running code is added up not just “unused” system memory? Could the lag be an indicator to circle the problem maybe?

That absolutely sound l like you are on the right track. I avoid global like the plague myself, although there are some situations when it is necessary and practically harmless.

Is there a scenario for using images in a scene, where ONLY the system memory on the device is showing a leak and it’s working fine on the simulator?

I now have looked into all the global stuff and admob and more.

But it still is happening on device. And the leak size of 500KB is showing it should be something big, right? So I now guess it is some image space maybe? What else can cause a 500KB increase in system memory every scene change and ONLY on the device?

I don’t know where to look at anymore. :frowning:

re your question.   No.  Composer should behave the same in simulator and on device.  
 
Question: 
So, you turned off all features that were not available or being used in the simulator and you see a difference in the way it runs/uses memory?
 
For Fun: 
Try setting these composer settings at the top of main.

local composer = require "composer composer.isDebug = true -- more messaging to console showing what composer is doing composer.recycleOnSceneChange = true 

Now, re-test in the simulator then on the device.

After that…

You may need to pay someone (or trade work with someone) to look at your game if you can’t figure it out and can’t live with it.

Thank you for the composer info.

I did use it and couldn’t find anything wrong BUT I afterwards was able to circle a function which was behaving differently on simulator and device. When looking into it I noticed there maybe are some graphics created which are not deleted properly with scene change.

I first found this strange because if so, this should be a problem on both the simulator AND on device, right? So I created a function for deleting the graphics before scene change to make sure. Testing this still showed a difference on the device, so I looked closer and found this:

I was using text display objects I created like this using the graphic image and created them “on” the image itself:

local gfx={} local groups={group} local createimages=function()      gfx.btn\_nextLVL=display.newImage("myimage.png",256,256)      gfx.btn\_nextLVL.theTextShadow=display.newText(options)      gfx.btn\_nextLVL.theText=display.newText(options)      -- put all in a group      groups.group=display.newGroup()      groups.group:insert(gfx.btn\_nextLVL)      groups.group:insert(gfx.btn\_nextLVL.theTextShadow)      groups.group:insert(gfx.btn\_nextLVL.theText) end 

I later removed the graphics with a scene change by calling a function which is doing this:

       for k,v in pairs( gfx ) do             if v then                 display.remove ( v )                 v=nil                 if gfx[k] then                     display.remove (gfx[k])                     gfx[k]=nil                 end             end             if #gfx then                 for x=#gfx,1,-1 do                     if gfx[x] then                         display.remove(gfx[x])                         gfx[x]=nil                     end                 end             end         end         for k,v in pairs( groups ) do             if v then                 display.remove ( v )                 v=nil                 if groups[k] then                     display.remove (groups[k])                     groups[k]=nil                 end             end             if #groups then                 for x=#groups,1,-1 do                     if groups[x] then                         display.remove(groups[x])                         groups[x]=nil                     end                 end             end         end

This seems to work on the simulator BUT not on the device because it seems (after testing) the memory for the text objects is not removed correctly on the device. When doing this for example (shown for a specific button image) for all images which are using this kind of display.newText objects:

     if gfx.btn\_nextLVL then         if gfx.btn\_nextLVL.theTextShadow then             display.remove(gfx.btn\_nextLVL.theTextShadow)             gfx.btn\_nextLVL.theTextShadow=nil         end         if gfx.btn\_nextLVL.theText then             display.remove(gfx.btn\_nextLVL.theText)             gfx.btn\_nextLVL.theText=nil         end         display.remove(gfx.btn\_nextLVL)         gfx.btn\_nextLVL=nil     end

This will remove more memory on device than it did before without this lines!

Is this possible? Can someone please test this and confirm?

I’m right now looking through all my code for this kind of added display.objects (text and other) to get my system memory leak removed. A big part already is now!

But the big question remains: Why is this only happening on device and not the simulator?

Can you reduce this to a simple test app that I can share with our engineers? 

Rob

Can I send you a personal link somehow?

If you file a bug report it will only go to us.

But you should be able to create a simple demo project that has minimal code without sharing your whole project.

Rob

I have created a file (zip) with a small project based on the composer sample file from the corona samples. Can I send this directly somehow?