Tuesday, September 4, 2012

Good Practices Prevent Memory-Related Problems

Objective-C provides two methods of application memory management.
  1. In the method described in this guide, referred to as “manual retain-release” or MRR, you explicitly manage memory by keeping track of objects you own. This is implemented using a model, known as reference counting, that the Foundation class NSObject provides in conjunction with the runtime environment.
  2. In Automatic Reference Counting, or ARC, the system uses the same reference counting system as MRR, but it inserts the appropriate memory management method calls for you at compile-time. You are strongly encouraged to use ARC for new projects. If you use ARC, there is typically no need to understand the underlying implementation described in this document, although it may in some situations be helpful. For more about ARC, see Transitioning to ARC Release Notes.

    Good Practices Prevent Memory-Related Problems

    There are two main kinds or problem that result from incorrect memory management:
  3. Freeing or overwriting data that is still in use
    This causes memory corruption, and typically results in your application crashing, or worse, corrupted user data.
  4. Not freeing data that is no longer in use causes memory leaks
    A memory leak is where allocated memory is not freed, even though it is never used again. Leaks cause your application to use ever-increasing amounts of memory, which in turn may result in poor system performance or (in iOS) your application being terminated.

No comments:

Post a Comment