0

Instruments でリークを実行したところ、値が 100% のメモリ リークが表示されます。問題の原因となっているコード行を確認できます。しかし、エラーが何であるかはよくわかりません..

- (void) listAllBooks {
    if (marrListFromDB != nil) {
        [marrListFromDB removeAllObjects];
        marrListFromDB = nil;
    }

    marrListFromDB = [[NSMutableArray alloc] init];
    ServerCommunicationAPI *servApi = [[ServerCommunicationAPI alloc] init];
    servApi.delegate = self;
    NSURL *url = [NSURL URLWithString:kLISTCONTENTS];
    [servApi listBooksWithDeviceID:singleton.g_strdevID deviceKey:singleton.g_strdevID andSessionString:singleton.g_strSessionID sessionKey:@"sessionKey" URL:url andRequestMethod:@"POST"];
}

エラーの行は最後の行です。なぜメモリリークを引き起こしているのかわかりません...いくつかのガイダンスが必要です..

4

3 に答える 3

0

もう 1 つのアイデア: 自動解放プールが設定されていない別のスレッドでコードを実行することはありませんか? この場合、送信されたメッセージは、servApi自動解放プールが存在しないため、後で解放できない自動解放オブジェクトを作成する可能性があります。
そのため、コードがメイン スレッドで実行されない場合は、@autoreleasepool {...}スレッドのブロックを使用して自動解放プールが設定されているかどうかを確認してください。

于 2013-02-06T07:26:17.553 に答える
0

提供された情報から判断するのは難しいですが、のデリゲート プロパティが?ServerCommunicationAPIとして宣言されている可能性があります。(strong)この場合servApi、それ自体への強い参照を保持しているため (保持サイクル)、解放されることはありません。
どの種類のオブジェクトが漏れているかを確認することをお勧めします。これにより、答えがはるかに簡単になります。

于 2013-02-06T07:07:19.420 に答える
0

これを試してみてください。メモリリークの問題が解決しますように。

- (void) listAllBooks {
if (marrListFromDB != nil) {
    [marrListFromDB removeAllObjects];
    marrListFromDB = nil;
}
ServerCommunicationAPI *servApi ;
marrListFromDB = [[NSMutableArray alloc] init];
if(servApi == nil){

     ServerCommunicationAPI *servApi = [[ServerCommunicationAPI alloc] init];
}//Every time it going to alloc. It's strong object may be due do this memory leak happens. 
servApi.delegate = self;
NSURL *url = [NSURL URLWithString:kLISTCONTENTS];
[servApi listBooksWithDeviceID:singleton.g_strdevID deviceKey:singleton.g_strdevID andSessionString:singleton.g_strSessionID sessionKey:@"sessionKey" URL:url andRequestMethod:@"POST"];

}

于 2013-02-06T07:18:22.103 に答える