How to fix memory leak?

After a long profile test, I found that in one of my ".m" file memory leaks occurs in the viewdidload section. I checked and xcode highlighted the part in which I had initialized arrays of collectors with values. my program uses collectors for user input. and I have 3 5 different views in my program. the first is a disclaimer, the second is a menu in which the user can select the type of calculation that he / she wants to do. Each calculation requires a specific input that the user enters from the collector. eg. one of the types has 5 inputs, which are processed by 5 different uipickers with separate arrays for storing values. these arrays are initialized with values ​​in the viewdidload method of this view. here is what i found after running the test:

-viewDidLoad .................................................. .................................................

instantiation

This is my first app development, and I'm a little confused about what to do. Any help would be greatly appreciated.

+5
source share
3 answers

Objects in object c have a save account. If this hold counter is greater than 0 when the object goes out of scope (when you stop using it), it flows.

The following things increase the number of deductions

  • [[alloc] init]
  • new
  • Copy
  • [save]
  • Adding an object to an array
  • adding an object as a child (e.g., view)
  • Most likely more, but you don't seem to use others in your code.

  • []
  • ,

, . ( - dealloc).

EDIT: ,

, , . , , , , , .

, :

-(init){
    ...
    stagePickerArray = [[NSMutableArray alloc] init];
    for (int i = 0; i < 3; i++)
    {
        //this string is autoreleased, you don't have call release on it.
        //methods with the format [CLASS CLASSwithsomething] tend to be autorelease
        NSString *s = [NSString stringWithFormat:@"%d", i);
        [stagePickerArray addObject:s];
    }
    ...
 }

, , , - , dealloc.

-(void) dealloc
{
    [stagepickerarray release];  //Do this for each of your arrays
    [super dealloc];
}
+4

, yo , . , , ,

NSString* answer = [NSString stringWithFormat: ...

, . -stringWithFormat: , , , , . , .

, - , , , - . stagePickerArray. , stagePickerArray -. -viewDidLoad, . , -dealloc.

+2

Objective-C . β†’ .

, , count = 1.

, , , . , 0, .

, - , . , , "" ( , ;)) release.

. iOS.

( - ARC - Automatic Retain Counting - iOS5! ios5

0
source

All Articles