Memory issue

Hi guys,

Please help me out here :slight_smile:

I have 22 sprites in images folder all having 3 sets of extensions:  .png, @2x.png and @4x.png

I have checked texture memory like this:

----------------------------- CHECK MEMORY local function checkMemory()    collectgarbage( "collect" )    local memUsage\_str = string.format( "MEMORY = %.3f KB", collectgarbage( "count" ) )    print( memUsage\_str, "TEXTURE = "..(system.getInfo("textureMemoryUsed") / (1024 \* 1024) ) ) end memTimer = timer.performWithDelay( 1000, checkMemory, 0 )

Memory is stable (does not increase over time).

But my problem is that on iPhone4 and iPhone5 I get 39MB of texture memory and on iPad Air I get 150MB of texture memory (all in simulator - I havent tried it on real device).

Total images folder size is 15,6MB.

No the weird thing comes.

I have purchased tinyPNG plugin and decreased images folder size is 5,16MB.

I have deleted big pictures and imported shrinked pictures and the texture memory stays the same (on iPhone4 and iPhone5 I get 39MB  and on iPad Air I get 150MB).

I have tried restarting my computer with no success.

1) What is going on here?

2) How can I have 150MB of texture memory when total file size of images folder is 15,6MB (after shrink 5,16MB)?

Waiting your reply

Many thanks :smiley:

Ivan

Are you using texts ?

I’m just having a guess and I could be totally wrong but, I believe fonts are actually converted as bitmap which means they "also consume texture memory just like displaying images.". So if their size is different (aka bigger) on iPad, that might explain it.

… But still, 150mb seems like quite a lot !

Hi evanspro,

I am not using any special fonts :frowning:
I am using besides already mentioned images:

  • few .lua libaries
  • 2 sound files (600kb total size)
  • few widget buttons…
    Nothing special really.

I loaded all sprites simultaneously from sprite.lua via an array table in level.lua

I do not get this, maybe I will try to copy all code in just main.lua (I am currently in composer scheme).

Ivan

I have just commented out following lines of code in level.lua:

-- local Sprites1 = require("sprite1") -- local Sprites2 = require("sprite2") -- local Sprites3 = require("sprite3")

Now iPhone4/5 texture memory is 8MB (before it was 39MB), and iPadAir texture memory is 27MB (before it was 150 MB).

Background and background elements are not inside sprite1.lua, sprite2.lua and sprite3.lua

So obviously memory leak is due images declaration inside sprite1.lua, sprite2.lua and sprite3.lua.

sprite1/2/3.lua looks like this:

local sheetInfo1  = require("player1") local myImageSheet1  = graphics.newImageSheet( "images/player1.png", sheetInfo1:getSheet() ) local sequenceData1  = {             {      name="dieLR",                                  -- name of the animation     sheet=myImageSheet1,                           -- the image sheet     start=sheetInfo1:getFrameIndex("dieLR1"), -- first frame     count=4,                                      -- number of frames     time=800,                                    -- speed     loopCount= 1,                                  -- repeat             },                                {      name="dieRL",                                  -- name of the animation     sheet=myImageSheet1,                           -- the image sheet     start=sheetInfo1:getFrameIndex("dieRL1"), -- first frame     count=4,                                      -- number of frames     time=800,                                    -- speed     loopCount= 1,                                  -- repeat                   }, } -- .... etc. until sprite22 -- Texture Packer was used to create sequences return Sprites1

Do you have any ideas   :( ?

Ivan

Images stored on disk are compressed so they use less space. Once an image is loaded, it’s decompressed into it’s natural file size. You can’t use the disk size as a measurement.  You have to take the image size (200 px X 400 px) and multiply them together then multiply again by 4 to get the in-memory size.  Thus that 200x400 image is 320,000 bytes in memory.  The @4x image you’re loading on the iPad are bigger than the @2x images you’re loading on the phone.   If your base 1x image is say 100 x 100 x 4 is 40,000 bytes of memory, The @2x version is: 200 x 200 x 4 or 160,000 bytes and the 400x400 @4x version is 640,000.

Your Retina images (@4x) eat up a lot of memory, but the iPad should have more memory to use so you should be okay.

Also you probably don’t have a leak, but normal memory usage. Leaks happen if the memory keeps going up and up and up and never stops.

Rob

Thank you Rob, great answer as always!

Are you using texts ?

I’m just having a guess and I could be totally wrong but, I believe fonts are actually converted as bitmap which means they "also consume texture memory just like displaying images.". So if their size is different (aka bigger) on iPad, that might explain it.

… But still, 150mb seems like quite a lot !

Hi evanspro,

I am not using any special fonts :frowning:
I am using besides already mentioned images:

  • few .lua libaries
  • 2 sound files (600kb total size)
  • few widget buttons…
    Nothing special really.

I loaded all sprites simultaneously from sprite.lua via an array table in level.lua

I do not get this, maybe I will try to copy all code in just main.lua (I am currently in composer scheme).

Ivan

I have just commented out following lines of code in level.lua:

-- local Sprites1 = require("sprite1") -- local Sprites2 = require("sprite2") -- local Sprites3 = require("sprite3")

Now iPhone4/5 texture memory is 8MB (before it was 39MB), and iPadAir texture memory is 27MB (before it was 150 MB).

Background and background elements are not inside sprite1.lua, sprite2.lua and sprite3.lua

So obviously memory leak is due images declaration inside sprite1.lua, sprite2.lua and sprite3.lua.

sprite1/2/3.lua looks like this:

local sheetInfo1  = require("player1") local myImageSheet1  = graphics.newImageSheet( "images/player1.png", sheetInfo1:getSheet() ) local sequenceData1  = {             {      name="dieLR",                                  -- name of the animation     sheet=myImageSheet1,                           -- the image sheet     start=sheetInfo1:getFrameIndex("dieLR1"), -- first frame     count=4,                                      -- number of frames     time=800,                                    -- speed     loopCount= 1,                                  -- repeat             },                                {      name="dieRL",                                  -- name of the animation     sheet=myImageSheet1,                           -- the image sheet     start=sheetInfo1:getFrameIndex("dieRL1"), -- first frame     count=4,                                      -- number of frames     time=800,                                    -- speed     loopCount= 1,                                  -- repeat                   }, } -- .... etc. until sprite22 -- Texture Packer was used to create sequences return Sprites1

Do you have any ideas   :( ?

Ivan

Images stored on disk are compressed so they use less space. Once an image is loaded, it’s decompressed into it’s natural file size. You can’t use the disk size as a measurement.  You have to take the image size (200 px X 400 px) and multiply them together then multiply again by 4 to get the in-memory size.  Thus that 200x400 image is 320,000 bytes in memory.  The @4x image you’re loading on the iPad are bigger than the @2x images you’re loading on the phone.   If your base 1x image is say 100 x 100 x 4 is 40,000 bytes of memory, The @2x version is: 200 x 200 x 4 or 160,000 bytes and the 400x400 @4x version is 640,000.

Your Retina images (@4x) eat up a lot of memory, but the iPad should have more memory to use so you should be okay.

Also you probably don’t have a leak, but normal memory usage. Leaks happen if the memory keeps going up and up and up and never stops.

Rob

Thank you Rob, great answer as always!