graphics.newImageSheet and RAM question

Hey guys,

I have a question regards to when the sprite sheet is loaded to memory?

I have a scene that contains lots of big sprite sheets, about 10 files of 1024x1024

The thing is, there is no scenario when 2 sprite sheets are used simultaneously, and also there is the fact that maybe not all of them will be used.

So thats why im asking about RAM, I want only the used sheets to be loaded to memory.

The way I set it up is like this for example:

[lua]
    local thunderOptions = {

        width =128,

        height = 128,

        numFrames = 64,

        sheetContentWidth = 1024, 

        sheetContentHeight = 1024,

        }

    local thunderSheet = graphics.newImageSheet ( “images/battleAttacks/thunderSheet.png” ,thunderOptions )

    local sequenceData = {

        – thunder ball 

            {    name = “thunderBall” ,sheet=thunderSheet ,frames = {1,2,3,4,5,6,5,4,5,6},loopCount = 1 ,time = 500 },

        

        – thunder from sky

            {    name = “thunderFromSky” ,sheet=thunderSheet ,frames = {10,11} ,time = 100 },

}

[/lua]

Is just by doing the code above, means that the sheet is already loaded to memory?

Then when im using this sheet I do :

[lua]local thunderFromSky = display.newSprite( thunderSheet, sequenceData )[/lua]

Hopefully only after this line of code the sheet is actually loaded.

One more question at the subject, is there a way to print to console the memory usage?

Currently im making a build and using instruments but its a lot of hassle.

Roy.

Hi Roy,

Simply loading the sheet doesn’t increase the texture memory, but displaying images/frames from it will.

To test your texture memory, most people use this function, running on a timer or Runtime loop:

[lua]

local function checkMem()

    collectgarbage(“collect”)

    local memUsage_str = string.format( “MEMORY = %.3f KB”, collectgarbage( “count” ) )

    print( memUsage_str, "TEXTURE = "…(system.getInfo(“textureMemoryUsed”)/1048576) )

end

timer.performWithDelay( 1000, checkMem, 0 )

[/lua]

Thanks for the fast reply!

Is texture memory any different from RAM usage? (only from the graphic point)

Cause im using 1024x1024 spriteSheets, but im getting a reading of only 

MEMORY = 308.811 KB    TEXTURE = 28.83203125

Is the  28.83203125 in mb? what is the different between “MEMORY” and “TEXTURE”?

And what are the limits of “MEMORY” and “TEXTURE”? on iPhone 4 (considering that its the lowest gen im targeting)

Thanks in advance

Roy.

Hi Roy,

System memory and texture memory are different, yes. Have you read the guide which talks about this a bit?

http://docs.coronalabs.com/guide/basics/optimization/index.html

@Bernet

Could you tell how newImageSheet behaves? Because you cannot perform remove on it, so I was wondering how it is managed in consideration of memory.

@POM

[lua]system.getInfo(“textureMemoryUsed”)/1048576[/lua] will give you result in MB

system.getInfo( “maxTextureSize” ) will give you proper size (simulator will probably return this value for computer not device)

If I remember well, 25MB is the safe rule if you want to target even weak devices

from forum:

Values in the literature for iOS devices & single apps are the following:

installed memory: 128 MB --> memory warning threshold: 20-25 MB

installed memory: 256 MB --> memory warning threshold: 80-90 MB

installed memory: 512 MB --> memory warning threshold: 260-300 MB (estimated)

Hi Roy,

Simply loading the sheet doesn’t increase the texture memory, but displaying images/frames from it will.

To test your texture memory, most people use this function, running on a timer or Runtime loop:

[lua]

local function checkMem()

    collectgarbage(“collect”)

    local memUsage_str = string.format( “MEMORY = %.3f KB”, collectgarbage( “count” ) )

    print( memUsage_str, "TEXTURE = "…(system.getInfo(“textureMemoryUsed”)/1048576) )

end

timer.performWithDelay( 1000, checkMem, 0 )

[/lua]

Thanks for the fast reply!

Is texture memory any different from RAM usage? (only from the graphic point)

Cause im using 1024x1024 spriteSheets, but im getting a reading of only 

MEMORY = 308.811 KB    TEXTURE = 28.83203125

Is the  28.83203125 in mb? what is the different between “MEMORY” and “TEXTURE”?

And what are the limits of “MEMORY” and “TEXTURE”? on iPhone 4 (considering that its the lowest gen im targeting)

Thanks in advance

Roy.

Hi Roy,

System memory and texture memory are different, yes. Have you read the guide which talks about this a bit?

http://docs.coronalabs.com/guide/basics/optimization/index.html

@Bernet

Could you tell how newImageSheet behaves? Because you cannot perform remove on it, so I was wondering how it is managed in consideration of memory.

@POM

[lua]system.getInfo(“textureMemoryUsed”)/1048576[/lua] will give you result in MB

system.getInfo( “maxTextureSize” ) will give you proper size (simulator will probably return this value for computer not device)

If I remember well, 25MB is the safe rule if you want to target even weak devices

from forum:

Values in the literature for iOS devices & single apps are the following:

installed memory: 128 MB --> memory warning threshold: 20-25 MB

installed memory: 256 MB --> memory warning threshold: 80-90 MB

installed memory: 512 MB --> memory warning threshold: 260-300 MB (estimated)

Hi, 

I’ve made some tests with 

collectgarbage()

print( "MemUsage: " … collectgarbage(“count”) )

local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000

print( "TexMem:   " … textMem )

in the enterFrame event, and according to the numbers shown, ‘graphics.newImageSheet’ increased TextMem by x amount.

After I nil the variables containing the ‘graphics.newImageSheet’ reference, the TexMem decreased the by x amount.

Example:

Increase TexTem

opt[8] = {width = 468, height = 250, numFrames = 1, sheetContentWidth = 468, sheetContentHeight = 250}

n1.p1 = graphics.newImageSheet(“1p.png”, opt[8])

Free TexMem

opt[8] = nil 

n1.p1 = nil

Cheers,

Ignacio

Hi, 

I’ve made some tests with 

collectgarbage()

print( "MemUsage: " … collectgarbage(“count”) )

local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000

print( "TexMem:   " … textMem )

in the enterFrame event, and according to the numbers shown, ‘graphics.newImageSheet’ increased TextMem by x amount.

After I nil the variables containing the ‘graphics.newImageSheet’ reference, the TexMem decreased the by x amount.

Example:

Increase TexTem

opt[8] = {width = 468, height = 250, numFrames = 1, sheetContentWidth = 468, sheetContentHeight = 250}

n1.p1 = graphics.newImageSheet(“1p.png”, opt[8])

Free TexMem

opt[8] = nil 

n1.p1 = nil

Cheers,

Ignacio