Welcome to my Programming Blog...

I am currently working on a couple of projects: An original game called "Implosion" which I am porting from Flash to the iPad, and a remake of Q*bert in Python (pygame), as part of the class I am teaching. Please feel free to use the "Labels" (at right) to follow a specific project or theme. If you are one of my Python students, I recommend that you check out the Python thread.

Monday, July 26, 2010

Memory problems...

I have been having a frustrating time with implosion. I had to take a week off for a conference, but even then, I've been avoiding it a little, in the hopes that something would come to me. And because I am frustrated.

As soon as my program starts, I get a memory warning, level 1. Soon thereafter, I get a level 2 warning, and the game crashes.

I finally got Instruments to show my memory leaks - it didn't find any. But it did show some large allocations at the beginning of the program. I found some code to tell me the remaining memory (http://adeem.me/blog/2009/04/01/get-the-amount-of-free-memory-available) and inserted into my startup routines.

Pretty quickly, I found that loading my main logo image, which was 1024 x1024 pixels, took up 5MB of my available 28MB. A bit steep-the file size was about a quarter of that, but I suppose it was compressed. So I reduced the file to 512x512, which reduced the memory used.

But I still got a memory warning.

A little investigation revealed that the memory warning was coming the second time the menu rendered. I soon found out that the first time the logo and buttons were drawn on the screen, it ate another 5MB, and the second time it ate an additional 5MB. But not the third. (I am guessing that this is a result of double-buffeting?)

So a quick loss of 15MB over a few seconds on a system where I start with only 28MB? No wonder the iPad was freaking out.

But there are two things bothering me at the moment.
1) something must be wrong with my numbers - the iPad I have is supposed to be 32GB, not MB. -- oops. I'm confusing storage space with RAM. It's pretty late as I write this.
2) when I take out the code that draws my logo and buttons, it still takes 5MB of RAM each time, even though it is not drawing anything! I am starting to think this is not my fault...

So I will have to research this online. Perhaps there is a fix for this, perhaps I can find a workaround, or perhaps... I don't know.

As I said, I am frustrated.
- Posted using BlogPress from my iPad

No comments:

Post a Comment