objective c - Reusing NSMutableArray -


While trying to reuse existing liters (to save memory), I need some leaks (obsolete by device ) Are getting.

Actually I am creating an NSMutableArray, filling it with objects (UIImages) and pass it on to another object which retains it. However, now I need to use an NSMutableArray again, I thought I would clear all of my items, empty it, and everything would be fine, but the device reports that calair leak object (??) That's what looks like:

  NSString * file name; NSMutableArray * arrayOfImages = [[NSMutableArray alloc] init]; // fill the array with images (int i = 0; i & lt; = 7; i ++) {fileName = [NSString stringWithFormat: @ "myImage_% d.png", ii] ;; [ArrayOfImages addObject: [UIImage imageNamed: fileName]]; } // Create a button with array AButton = [[with customButtonClass button type UIButtonTypeCustom] initWithFrame: someFrame imageArray: arrayOfImages]; // Release for your objects (Int ii = 0; I & lt; [ARROIFIge count]; I ++) [[ARROIF images] ObjectExt: I] release]; } // empty array [delete allObjects] [arrayOfImages]; // fill it with other images (int i = 0; i & lt; = 7; i ++) {fileName = [NSString stringWithFormat: @ "myOtherImage_% d.png", i]; [ArrayOfImages addObject: [UIImage imageNamed: fileName]]; } // Create another button with other images (same array) aSecondButton = [[CustomButtonClass Button WithType: UIButtonTypeCustom] initWithFrame: someFrame imageArray: arrayOfImages]; [ArrayOfImages release];  

For clarity, my button init method looks like this:

  - (id) initWithFrame: (CGRact) frame picture: (NSArray *) Imagery {if (self = [super initwithframe: frame]) {myImageArray = [[NSA arraylineArera: imageArere] has been maintained;)} healthy return; }  

I know that I can only create a new NSMutableArray and can be more than this problem, but I'm annoyed that I just can not reuse the old array I am What can be the problem?

I'm getting some leaks (obvserved by the tool) to save the current NSMutableArray (Memory For) is trying to reuse.

An array actually takes small amounts of memory; 4 bit bytes per pointer (on 32 bit system) + A small portion of the overhead is a time-consuming waste to try to save memory, but in the most extraordinary circumstances.

// for its objects (int i = 0; i & lt; [arrayOfImages count]; I ++) {[arrayOfImages ObjectIntext: i] release]; } // empty array [delete allObjects] [arrayOfImages];

You did not place items and, thus, you should not release them! After the above signals that your app has not crashed, you want to keep objects more than anywhere else.

I know that I can only create a new NSMutableArray and can be more than this problem but it does not bother me not only to be able to reuse the old array What can be the problem?

There is nothing in the code that has emerged as a memory leak; You have more leakage than objects.

And the above indicates that for you to create an array that releases the array and to create a new one you will have to actually look again, again it is actually nothing to do with it.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -