Note that there are some explanatory texts on larger screens.

plurals
  1. POObj-C UIActionSheet Memory Leaks iPhone
    text
    copied!<p>I'm coding a popup screen that will show up if a the value for <code>mulValue</code> in the settings is <code>nil</code>. Here is the code:</p> <pre><code>#import "FirstViewController.h" @implementation FirstViewController @synthesize myHelpfile = ivHelpfile; //UIAlertView @synthesize myAboutfile = ivAboutfile; //UIAlertView @synthesize myNoarea = ivNoarea; //UIAlertView @synthesize myMap = ivMap; //UIImageView @synthesize myAreapick = ivAreapick; //UIActionSheet @synthesize myAdvancedmode = ivAdvancedmode; //NSString @synthesize myAreaset = ivAreaset; //NSString @synthesize myAreaarray = ivAreaarray; //NSArray @synthesize appSettingsViewController, settingsViewController; - (void)viewDidLoad { [super viewDidLoad]; self.title = @"Wildlife"; NSString *area = [[NSUserDefaults standardUserDefaults] stringForKey:@"mulValue"]; [self setMyAreaset:area]; if ([self myAreaset] == nil) { //check if any region is selected. If not, push UIActionsheet NSArray *array = [[NSArray alloc] initWithObjects: // creating array for different regions [NSString stringWithString:@"Region 1"], [NSString stringWithString:@"Region 2"], [NSString stringWithString:@"Region 3"], [NSString stringWithString:@"Region 4"], [NSString stringWithString:@"Region 5"], [NSString stringWithString:@"Region 6"],nil]; [self setMyAreaarray:array]; [array release], array = nil; NSLog(@"Built areaselectArray"); NSLog(@"Values of areaselectArray are %@",[self myAreaarray]); UIActionSheet *areaselect = [[UIActionSheet alloc] initWithTitle:@"Select your current area" //creation of popup Area Selection delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; [self setMyAreapick:areaselect]; [areaselect release], areaselect = nil; int countarray = [[self myAreaarray] count]; for (int i = 0; i &lt; countarray; i++) { //building list from array [[self myAreapick] addButtonWithTitle:[[self myAreaarray] objectAtIndex:i]]; } [[self myAreapick] addButtonWithTitle:@"Cancel"]; [self myAreapick].cancelButtonIndex = countarray; [[self myAreapick] showInView:self.view];//show the general UIActionSheet instance NSLog(@"Out of viewDidLoad"); } else { NSLog(@"Area is %@, no need for areaselectArray",area); } } -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger )buttonIndex { int countarray = [[self myAreaarray] count]; if (buttonIndex != countarray) { //cancel button is at countarray, so for anything that is not cancel, do: NSString *area = [[self myAreaarray] objectAtIndex:(buttonIndex)]; [self setMyAreaset:area]; [[NSUserDefaults standardUserDefaults] setObject:[self myAreaset] forKey:@"mulValue"]; [[NSUserDefaults standardUserDefaults] synchronize]; //sync NSLog(@"Released areaselectArray"); } else { } } </code></pre> <p>And in my FirstViewController.h I have:</p> <pre><code>@interface FirstViewController : UIViewController &lt;UIActionSheetDelegate, IASKSettingsDelegate, UIAlertViewDelegate&gt; { UIAlertView *ivHelpfile; UIAlertView *ivAboutfile; UIAlertView *ivNoarea; UIActionSheet *ivAreapick; UIImageView *ivMap; NSString *ivAdvancedmode; NSString *ivAreaset; NSArray *ivAreaarray; } @property(nonatomic, retain) UIAlertView *myHelpfile; @property(nonatomic, retain) UIAlertView *myAboutfile; @property(nonatomic, retain) UIAlertView *myNoarea; @property(nonatomic, retain) UIActionSheet *myAreapick; @property(nonatomic, retain) UIImageView *myMap; @property(nonatomic, copy) NSString *myAdvancedmode; @property(nonatomic, copy) NSString *myAreaset; @property(nonatomic, retain) NSArray *myAreaarray; </code></pre> <p>When I run my app in the simulator with Instruments running, I get a memory leak whenever I scroll the list of rows (as built by <code>[self myAreaarray]</code>) and release my finger. The weird thing is, it has not really done anything else at that point. The main view is loaded, but it would be strange that that would cause a memory leak based on scrolling through the list. </p> <p>The leaks I get in Instruments are the following:</p> <p>_NSCFType 48 bytes CoreGraphics CGTypeCreateInstanceWithAllocator</p> <p>UIDeviceWhiteColor 16 bytes UIKit +[UIColor allocWithZone:]</p> <p>When I scroll through the list again, more of those errors show up. It looks like I'm allocating something and not releasing it (while I'm scrolling the list?), but I can't find it at this point. </p> <p>Any help would be appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload