Why oh why do I have a memory leek.

This post will not tell you how to find and fix your memory leek but I intend to show you the most common cause of a memory leek.
A memory leek happens when you delete a pointer, but don’t delete the memory it is pointing to. Pointers are created with an *, like the following.

int *pointer;

A pointer points to a position in memory, and the computer allocates the space for the value you as a programmer put into the pointer. If you delete the pointer, without first telling the computer you no longer needed the allocated space, you will never be able to access that space. The computer will not use that space because it thinks that you are using it.
It would be like if you parked your car in a city and then forgot were you parked it. No one else would be able to park in the space because your car is there but you are not using the car. The space is not being used in a constructive way and there is no way for you to access it therefore it is a memory leek.
So remember every time you create a pointer don’t delete the pointer without deleting the data it points to first.

Copy right Britney Lee Johnson September 2010.

This entry was posted in cocos2d. Bookmark the permalink.

5 Responses to Why oh why do I have a memory leek.

  1. Genial post and this fill someone in on helped me alot in my college assignement. Gratefulness you for your information.

  2. admin says:

    Thank You I am glad it helped you.

  3. Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.

  4. I really like the way you explained pointers. The analogy with the car and the parking lot was excellent. Also noticed that you started putting up some cocos2d snippets, have you developed anything yet? Just wondering because I started using cocos a few weeks ago. It would be nice to have someone to bounce ideas off of…

    I’m no expert but have been developing with Objective-C for quite some time now. So if you have any questions or need any help I’d be happy share some knowledge

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>