Category Archives: memory management

Debug reference counting for any class

In a previous post, I mentioned a trick that I sometimes use to debug memory issues where a class I own is either being released too soon (often resulting in a EXC_BAD_ACCESS exception), or is leaked, resulting in low memory. The main idea was to temporarily override key methods such as retain, release, and autorelease […]

Memory Warnings

This post gives a quick intro to dealing with memory warnings in iOS. I have to admit, I’ve avoided this subject for a looong time while learning iOS.  The first word says “these bugs will be incredibly annoying” and the second word says “you can just ignore these.”  Or rather, that’s what the back of […]

Memory management guidelines

In this post, I’ll outline four simple rules for memory management in Objective-C. The Apple docs have already established basic guidelines for object ownership, following the fundamental idea that if you own an object, then you’re responsible for releasing it. This post goes a step further with tips for when and where ownership can be […]

let it be

This post explains one of my favorite NSObject categories – one that is extremely universal and handy for shorter and, in my opinion, more memory-manageable code.  (Code below.) Edit: Commenter David found a bug in this implementation. Check out the fixed version here; the new source files are listed at the bottom of that post. (The […]

feeling retained?

This is a quick tip for figuring out why an object is not being released when you expect it to: For the object in question, override retain and release to log their activity. Don’t forget that alloc is always called first, so if you see an equal number of retain and release logs, this means […]