iphone - NSMutabledata. Why is the retain count 1 higher that I would have expected? -


I am trying to do daily everyday, getting my exercise, and making sure I make myself Keep balance between keeping and releasing.

Here's what I'm surprised. I have an ivar:

  NSMutabledata * _alignmentData   

and a synthesized property associated with it:

  // H file @ property (nontamic, write) NSMutableData * alignment data; // M file @ synthesis alignment data = _alignmentData;  

I start pulling data from asynchronous server:

  self.connection = [[[NSURL connection alloted] initWithRequest: theRequest delegate: self] Autorelease];  

And immediately after using data buffer in asynchronous callback:

  // This print is 0. Cool NSLog (@ "First [_alignmentData retainCount] =% d", [_alignmentData retainCount]); // Create a space to get data from asynchronous data: self.alignmentData = [NSMutableData data]; // print it 2. it should be 1?!? NSLog (@ "[_alignmentData retainCount] =% d" later, [_alignmentData retainCount]);  

To compile cases in the first asynchronous callback to the fire after the above allocation of self-alignment data, I inspect the count again:

  - (zero) connection: (NSURLConnection *) connection was reception: (NSURLResponse *) response {// it prints 1. NSLog (@ "[_Number of alignment data retention] =% d", [_alignmentData RetainCount]); [Self. Alignment set length: 0]; }  

It seems that the count of maintenance increases from 2 to 0, then falls to 1. Can anyone tell me how is this possible?

Note: I have been told that do not use the number of maintenance as a debugging aid, but it is not practical only in objective non-trash collecting language.

This is not practical for the use of maintaining debugging as a support, in fact it is experienced -C is a codec that will tell you that they will not pay attention to maintaining calculations. Those who are generally worried about them, they are new coders for purpose-C, and they have become confused like you.

You should not worry too much about counting the fact that something more than expected is maintained by you, nothing is necessary with your code and it is not necessary that You point to the bug, and the only way to determine whether to use the proper debugging tool as if you were advised in the first place.

In this particular case, 2 is the calculation of maintaining the right for that object as it was created with the number of maintenance of 1, then it is maintained by your setter method.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -