Memory issues

Hi guys, i’m currently building an education app for young kids and have run into an issue with memory, at least I think thats what it is.
I have a menu screen on startup, with 6 options. My first buttons brings you to a section with flashcards. These flashcards are based on the alphabet and use a sliding function to scroll through them. Each card has a number of areas where a user can touch to hear a sound. At the moment its taking between 5 and 7 seconds to load the flashcard scene using director. Is there a way to pre-load the sounds(mp3s) and background images for each slide(26 jpgs) in the main.lua file or someplace else to cut down on loading times between scenes?
I have a LOT of functions in my flashcard.lua file for triggering sounds when areas of the display are tapped.

My sounds also won’t trigger when testing on ipad but will trigger on iphone.

Any thoughts?

Thanks [import]uid: 92074 topic_id: 17249 reply_id: 317249[/import]

Hey there - let’s start by taking a look at your memory usage to establish whether or not this is the issue. Put this in your project, play a bit and see what is being printed in the simulator;

[lua]local function monitorMem(event)
collectgarbage(“collect”)

print( “\nMemUsage: " … (collectgarbage(“count”)/1000) … " MB”)
print("Texture Usage " … system.getInfo( “textureMemoryUsed” ) / 1000000)

return true
end

Runtime:addEventListener(“enterFrame”, monitorMem)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 17249 reply_id: 65166[/import]

Hi Peach,
I popped that code into my project and had a look in the terminal. This is the result:

“MemUsage: 0.1603486328125 MB
Texture Usage 28.34432”

To be honest, I don’t know what that means.
I was originally using PNGs with transparency for each of the slides for the flashcards on a static background. You can see it in action here: http://www.youtube.com/watch?v=Q2lIl8AiAdk. The flashcard section is at 0.32 in the video. It loads pretty slowly. I decided to use much smaller file size JPGs instead of the PNGs (without transparency, with background incorporated). Likewise for the sounds, I was originally using WAVs but changed to MP3s for smaller file size because my build was huge (over 30mb).

Can images or sounds be loaded in the main.lua or menu.lua files, and then called later on in different scenes? [import]uid: 92074 topic_id: 17249 reply_id: 65233[/import]

If the variables you store the references to the loaded audio in are global in scope, you should be able to play them from anywhere.

You might run into an issue with filling up your available memory early by front loading the audio, so be on the lookout for that.

With regards to the memory monitor code that Peach provided, are the numbers in the terminal rising and falling as you move through your app? Or is one set of numbers continually going up?

Rising and falling is the expected behavior. If one or both of the numbers is continuing to rise, it suggests a memory leak. [import]uid: 5317 topic_id: 17249 reply_id: 65255[/import]

Hi mike4, the numbers in the terminal are rising and falling depending on what part of the app I’m in.
Regarding the global variables, how do you go about calling them in other scenes? Will this work with images too? [import]uid: 92074 topic_id: 17249 reply_id: 65326[/import]