Ram
Ram

Reputation: 2513

whats the difference between releasing an object inside dealloc or releasing in the same method where we init it?

HI, I am working on optimizing my iphone project for proper memory management. my question is:

what's the difference between releasing an object inside dealloc or releasing in the same method where we init it?

Thanks!

Upvotes: 0

Views: 61

Answers (1)

mipadi
mipadi

Reputation: 411192

Generally, you want to release an object as close to the point in the code where you initialize it as possible. If you have local variables in a method that you are init-ing, you release them before the method returns.

This, however, is not possible with instance variables, since they stick around with the objects; thus, you release them in a dealloc method.

Upvotes: 2

Related Questions