2011-03-08 9 views
1

설정에서 mulValue의 값이 nil 인 경우 표시되는 팝업 화면을 코딩하고 있습니다. 여기에 코드입니다 :Obj-C UIActionSheet 메모리 누수 iPhone

#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 < 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 { 
    } 

} 

그리고 내 FirstViewController.h에서 내가 가진 : 나는 악기가 실행하는 시뮬레이터 내 응용 프로그램을 실행하면 나는 목록을 스크롤 할 때마다

@interface FirstViewController : UIViewController <UIActionSheetDelegate, IASKSettingsDelegate, UIAlertViewDelegate> { 
    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; 

, 나는 메모리 누수를 얻을 수 ([self myAreaarray]으로 작성) 행을 시작하고 내 손가락을 뗍니다. 이상한 점은 그 시점에서 실제로 다른 것을하지 않았다는 것입니다. 기본보기가로드되었지만 목록을 스크롤하는 것을 기반으로 메모리 누수가 발생한다는 것은 이상 할 것입니다.

I 악기 드릴 누출하면 다음과 같다

_NSCFType 48 바이트있는 CoreGraphics CGTypeCreateInstanceWithAllocator

UIDeviceWhiteColor 16 바이트 UIKit + [UIColor allocWithZone을 :]

I 다시 목록을 스크롤 자세히 이러한 오류가 표시됩니다. 그것은 무언가를 할당하고 그것을 공개하지 않는 것 같습니다 (목록을 스크롤하는 동안?),하지만이 시점에서 찾을 수 없습니다.

도움이 될 것입니다.

답변

0

난 그것에서 모든 응용 프로그램 코드를 추출,뿐만 아니라 그것을보고 있어요 :

UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"Test" delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 

for (int i = 0; i < 100; i++) { 
    [as addButtonWithTitle:[NSString stringWithFormat:@"Button %i", i]]; 
} 
as.cancelButtonIndex = 99; 
as.destructiveButtonIndex = 0; 

[as showInView:self.view]; 
[as release]; 

악기 메모리 누수 프로파일 러를 통해 실행, 액션 시트의 각 디스플레이가 yieds 6 UIDeviceWhiteColor 누출 4 CGColor 누수 . 이게 UIKit의 버그 인 것 같아.