Importance of memory management

Member
Posts: 65
Joined: 2009.01
Post: #1
I am preparing some lecture material for new learners of Objective-C and iPhone game programming. I am contemplating the issue of how much emphasis to give to the topic of memory management. My sense is that a beginner can get into a lot of trouble with it, and I wonder if memory leaks even matter in iPhone game programming.
As I am not a professional programmer, I am hoping some of you could share real-world anecdotes of memory leaks causing problems in a game.
Thanks.
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #2
Just based on that post, I suggest you don't try to create lecture material, as memory management is probably one of the most important things, especially on the iPhone. No offense, but it doesn't seem like you know the subject well enough to prepare anything useful to others, especially beginners.
Quote this message in a reply
Member
Posts: 65
Joined: 2009.01
Post: #3
Actually, it is because I do understand memory management that I am able to question the importance of teaching it to beginners. I am a professor, (not of computer science, though I do hold a degree in electrical engineering), so I know that a lot of what is included in the formal training of any subject is based more on tradition than any real practicality.
So, I don't think it unreasonable to wonder if memory leaks really matter in iPhone game programming and, if so, under what circumstances.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
johncmurphy Wrote:Actually, it is because I do understand memory management that I am able to question the importance of teaching it to beginners. I am a professor, (not of computer science, though I do hold a degree in electrical engineering), so I know that a lot of what is included in the formal training of any subject is based more on tradition than any real practicality.
So, I don't think it unreasonable to wonder if memory leaks really matter in iPhone game programming and, if so, under what circumstances.

It would only be unreasonable to wonder about that if you had any practical experience, someone in that situation that didn't know the details of it would be very problematic (and possibly dangerous).

memory leaks are a problem and can cause several bad symptoms which can disable your program or even take down the whole OS.

Again not in a nasty way but I agree with DoG that you should avoid going into detail about something like this which you haven't had experience with.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 65
Joined: 2009.01
Post: #5
unknown Wrote:Again not in a nasty way but I agree with DoG that you should avoid going into detail about something like this which you haven't had experience with.
I don't take any offense and I thank you for your responses.
This may seem odd, but teaching at the university level (any curriculum) in the United States usually does not require any practical experience. There's a joke, "Those that can do, those that can't teach."
I have no shame in relying upon the practical experiences of others when creating my teaching material. I, and other professional educators, make no secret of the fact that we are best at presenting theoretical material to learners, not actually getting something to work.
So I accept your responses and will include material on memory management.
Please check out what I have so far
http://www.johncmurphy.com/product.aspx?pid=365
I welcome suggestions on how to improve it.
Quote this message in a reply
Member
Posts: 269
Joined: 2005.04
Post: #6
Off the top of my head I can only think of one well-written story of a memory bug gone horribly wrong.

http://wilshipley.com/blog/2008/07/pimp-...ug-of.html

Quote:and I wonder if memory leaks even matter in iPhone game programming.

Absolutely. Arguably even more than on modern Mac OS X / Windows programming. The iPhone doesn't have a virtual memory system, and has highly constrained system RAM. If your app starts using too much memory, the OS is going to kill your app. And if your app seemingly crashes all the time, you're going to get some bad reviews. Smile
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #7
Bachus Wrote:Absolutely. Arguably even more than on modern Mac OS X / Windows programming.
I'd go ahead and just drop the "Arguably" out of that. Wink

Bachus Wrote:The iPhone doesn't have a virtual memory system, and has highly constrained system RAM.

From what I understand, technically by design, it *does* have a virtual memory system, but apparently they cut out the part that does the paging to disk, so yeah, I guess you could argue that it doesn't have a virtual memory system in any practical sense... Sneaky

johncmurphy Wrote:So, I don't think it unreasonable to wonder if memory leaks really matter in iPhone game programming and, if so, under what circumstances.
Yes, they can matter big-time on iPhone! You're right that memory leaks are kind of being neglected on desktop systems nowadays, but really, there isn't enough room on iPhone to ignore them. We're practically limited to <20 MB of RAM before the OS starts peeing in the coffee with memory warnings. It's true that RAM is currently a precious commodity on iPhone right now and memory leaks cannot be casually ignored under most circumstances.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #8
johncmurphy Wrote:Please check out what I have so far
http://www.johncmurphy.com/product.aspx?pid=365
I welcome suggestions on how to improve it.

I watched that first video, and it looks pretty neato! I can't say I've seen anything quite like it. You cover a *lot* of ground in one relatively short video. There were a few little things here and there that came to mind but nothing worth mentioning (that I can remember anyway, since it moved so fast I didn't have time to commit any thoughts to memory). It must've taken a lot of work to put that together. Smile
Quote this message in a reply
Member
Posts: 65
Joined: 2009.01
Post: #9
AnotherJake Wrote:You cover a *lot* of ground in one relatively short video.
It's temporally compressed for use as a reference, which works for adult learners.
AnotherJake Wrote:I can't say I've seen anything quite like it.
Thank you. I'll take that as a compliment. I think your comment illustrates my point that teachers know HOW to teach, but we rely on the practical experience of others to know WHAT to teach. I fact, I relied heavily on the discussions that occur here in this forum during the making of those videos.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #10
Yes, definitely meant as a compliment Wink I'd say that if you don't know what you're talking about, you at least do a darn good job of faking it. Rasp

I was just thinking that I had actually read about the iPhone virtual memory system in the iPhone programming guide last year (as opposed to blogs, which is where I thought I had read it also), so I went back to see if I could find that info again, and sure enough it's right there. So yes, basically what's up is that the iPhone *does* have a virtual memory system, but it *doesn't* write volatile pages to disk; so when you run out of physical RAM, you run out of physical RAM. To deal with this, memory warnings are sent to all applications so they can unload unneeded resources like views that aren't visible. The iPhone programming guide clearly states that since memory is a critical resource on iPhone, memory leaks must be eliminated. And from my own experience, you definitely do not want any memory leaks on iPhone. ... Not to mention one really critical point we've all neglected to bring up: A leaking application is grounds for app rejection from the App Store!
Quote this message in a reply
Member
Posts: 177
Joined: 2002.08
Post: #11
AnotherJake Wrote:From what I understand, technically by design, it *does* have a virtual memory system, but apparently they cut out the part that does the paging to disk, so yeah, I guess you could argue that it doesn't have a virtual memory system in any practical sense... Sneaky

It still has virtualized addresses and can perform memory mapping, so it's virtual memory by any technical definition.

It's interesting that the bug in the linked blog didn't hit a per-process limit before it hit the system limit, that's the normal way of protecting Unix derivatives against resource leaks.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #12
Mark Levin Wrote:It still has virtualized addresses and can perform memory mapping, so it's virtual memory by any technical definition.

It's interesting that the bug in the linked blog didn't hit a per-process limit before it hit the system limit, that's the normal way of protecting Unix derivatives against resource leaks.

As I wrote in the post just above, after I RTFM again:

Quote:So yes, basically what's up is that the iPhone *does* have a virtual memory system, but it *doesn't* write volatile pages to disk; so when you run out of physical RAM, you run out of physical RAM.

Leak memory on purpose and you'll eventually crash the device. So if you think about it, since they aren't allowing any disk swap and the memory is virtualized, there isn't really any practical way to have a per-process limit. ... at least not that I can imagine ATM.

Well, I guess you *could*, but I'm not sure how useful it'd be when system RAM is so limited in the first place.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Objective C memory management Madrayken 3 2,877 Jul 10, 2009 10:13 AM
Last Post: DoG
  Input Management bmantzey 9 3,925 Sep 24, 2008 06:26 AM
Last Post: bmantzey
  GUI Management Design Nick 14 5,191 Nov 24, 2006 06:07 AM
Last Post: memon
  Input Management chainsawmcgraw 4 3,539 Nov 5, 2003 09:00 AM
Last Post: DoG