3

私のアプリの1つで、UIKit、UIFoundation、QuartzCoreでメモリリークが発生しています。コールツリーに行くと、リークが表示されmain.mます。なぜこれが起こっているのか、私にはまったくわかりませんでした。以下に、メモリリークのスクリーンショットを示します。ここに画像の説明を入力してください

コールツリー内

ここに画像の説明を入力してください

このリークを解決するにはどうすればよいですか?

メモリリークコード

- (void) showCustomPrices
{

int priceValue = 0;
NSArray* priceSplitValue = [btnpriceButton.titleLabel.text componentsSeparatedByString: @"."];
NSString* priceFinal = [priceSplitValue objectAtIndex:0];

for(int i=0;i<[priceArray count];i++)
{ 
    if([[priceArray objectAtIndex:i] isEqualToString:priceFinal]){
        priceValue = i; 
    }
}


    //Assign the cocktail to picker view
    priceActionsheet = [[UIActionSheet alloc] initWithTitle:nil
                                              delegate:self
                                     cancelButtonTitle:nil
                                destructiveButtonTitle:nil
                                     otherButtonTitles:nil];//as we want to display a subview we won't be using the default buttons but rather we're need to create a toolbar to display the buttons on

    [priceActionsheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

    CGRect pickerFrame = CGRectMake(0, 40, 0, 0);

    pricePickerview = [[UIPickerView alloc] initWithFrame:pickerFrame];
    pricePickerview.showsSelectionIndicator = YES;
    pricePickerview.dataSource = self;
    pricePickerview.delegate = self;


    [priceActionsheet addSubview:pricePickerview];
    //[pickerView release];

    priceToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 485, 44)];
    priceToolbar.barStyle = UIBarStyleBlackTranslucent;
    [priceToolbar sizeToFit];

    NSMutableArray *barItems = [[NSMutableArray alloc] init];

    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [barItems addObject:flexSpace];

    UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
    [barItems addObject:doneBtn];

    UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
    [barItems addObject:cancelBtn];

    [pricePickerview selectRow:priceValue inComponent:0 animated:YES];//Memory leaks shows 100% here

    [priceToolbar setItems:barItems animated:YES];

    [priceActionsheet addSubview:priceToolbar];

    [priceActionsheet addSubview:pricePickerview];

    [priceActionsheet showInView:self.view];  

    [priceActionsheet setBounds:CGRectMake(0, 0, 485, 320)];

}

どんな助けでも大歓迎です。

4

4 に答える 4

1

[super dealloc];プロジェクトがARC以外の場合は、基礎クラスのサブクラス化をどこかに残したことが原因である可能性があります。のサブクラスでも同じ問題が発生しましたNSObject。私は書くのを忘れていて[super dealloc];、似たようなリークが発生していました。

于 2012-11-30T17:24:46.930 に答える
1

最後に、ピッカー ビューallocation/initialisationパーツをメソッドから にshowCustomePrices移動することで問題を解決しましたviewwillAppear。これは、メモリリークなしで素晴らしく機能します。

以前に起こったことは、ボタンをクリックするたびpickerviewにメモリ割り当てがポップアップすることです。それがメモリリークが発生した理由です。

ビューviewwillAppearがロードされたときに最初に割り当てるだけです。次に、メモリを割り当てずに Picker View にアクセスします。したがって、メモリリークは削除されます。

于 2012-12-04T09:08:59.870 に答える
0
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;

これを main.m で試してください

于 2012-12-04T11:37:57.047 に答える
-1
int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, @"yourAppName", nil);
    [pool release];
    return retVal;
}
于 2012-12-04T12:09:35.710 に答える