Why not to use ARC, from Pivotal labs

One of problems I felt with ARC was that… it actually makes thing more difficult.

Here is some good explanation.

So, it makes easy stuff easier, but difficult stuff more difficult.

Yes. That’s my gut feeling.

BTW, I don’t understand why people had difficulty in memory management. Probably new S/W engineers are spoiled already got used to easier languages which usually doesn’t require memory management?
At some companies, I noticed that they didn’t have good pattern in memory management. That is.. they allocated new memory space at any time and deallocated it at any time.

Rule of thumb is like this.
If an object is going to have a life span as long as its containing object or almost similar life span, try to allocate it when the containing object is created and release it when the containing object is to be released. In other words, allocate in a constructor and release it in destructor.

Second rule is that if it’s created in a function, try to release it in the function right after you finish using it.If a function is to return the newly allocated object, name the function to reflect that it creates a new object and will return the object.

Third rule is to make clear object ownership.

I have seen many functions and methods in which they create a new object but the method/function names don’t imply or state the fact. Then it becomes very hard to trace where one object is created and when it’s destructed. ( destroying is also same. )

If those simple rules are kept, memory management becomes very “manageable” and “easily understandable” when a new person to an existing project starts to work on it. Also it is very easy to debug and figure out from when to when they are alive.

A consistent pattern is very important to make piece of code manageable.

About these ads

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 47 other followers

%d bloggers like this: