0

Possible Duplicate:
Why shouldn’t I use the getter to release a property in objective-c?

I am little bit confused on alloc and release with self. After looking to several post and tutorials there seems that more suggestions needed on this. Following are the list of questions:

  1. Is this a correct way to alloc and release. self.selectPopover = [[UIPopoverController alloc] init];

[self.selectPopover release];

  1. Trying to execute this code from another class. classArr is define in ObjClass. When i analyze this code potential leak "Incorrect decrement of the reference count of an object that is not owned at this point by the caller" is occured.

ObjClass.classArr = [[NSMutableArray alloc]init];

[ObjClass.classArr release];

So anyone can clear my doubts on this. Thanks in advance.

Community
  • 1
  • 1
iamsult
  • 1,581
  • 1
  • 15
  • 21

2 Answers2

2

you can understand the concept you are looking for via this post:

Objective-C Difference between setting nil and releasing

Community
  • 1
  • 1
0

I am assuming that you have created the property as retain
when you
ObjClass.classArr = [[NSMutableArray alloc] init];
At this point the retainCount becomes two, one because of alloc and one by assigning it through property which is of type retain
and when you [ObjClass.classArr release]; at this time you send one release and the reatinCount become 1 from 2.
So either you do like this

ObjClass.classArr = [[NSMutableArray alloc]init];
[ObjClass.classArr release];

which makes its retain count to one
Or you can do like this which is the case which actually happens

   classArr = [[NSMutableArray alloc] init];

assigning ivar without property which make retainCount one.

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184