English 中文(简体)
标C 供我用的共同记忆泄露
原标题:Object C common memory leaks for me

当在文书中对这一守则进行描述时,我发现35名运动员的记忆泄露。 如何应对以避免记忆泄露?

NSMutableArray *players = [NSMutableArray array];
NSData *data = [theRequest responseData];
NSArray *array = (NSArray *) [decoder objectWithData:data];
int len = 35;
for (int i = 0; i < len; i++) {
    NSDictionary *dic = (NSDictionary *) [array objectAtIndex:i];

    Player *p = [[Player alloc] init];
    p.playerID = [dic objectForKey:@"id"];
    p.name = [dic objectForKey:@"name"];
    p.country = [dic objectForKey:@"country"];
    p.club = [dic objectForKey:@"club"];
    p.imageURL = [dic objectForKey:@"image"];
    p.likeNumber = [dic objectForKey:@"like_number"];
    p.likeTime = [dic objectForKey:@"like_time"];
    p.likePlayerID = [dic objectForKey:@"like_player_id"];
    p.likeDeviceID = [dic objectForKey:@"like_device_id"];
    p.disLikeNumber = [dic objectForKey:@"dislike_number"];
    p.disLikeTime = [dic objectForKey:@"dislike_time"];
    p.disLikePlayerID = [dic objectForKey:@"dislike_player_id"];
    p.disLikeDeviceID = [dic objectForKey:@"dislike_device_id"];

    [players insertObject:p atIndex:i];
    [p release];
}
最佳回答

也许会认为,在法典的末尾,你的参与者正在失去。

或者说,它会混淆阵列的地位。

它是否抱怨说,如果你制造了带有冲积层的 mu阵,而不是阵列: (没有保留地的通用阵列确实使分配库全然如此。)

问题回答

The code shown above is correct. The leaks are likely coming from something else that is retaining and not releasing a Player object.

请注意,Leaks仪器只显示被泄露的物体被分配在何处,而不是发生不正确的记忆管理。 然而,如果你在被泄露的物体之一旁边点上小小小小小arrow,你实际上可以看到该物体的整个保留/释放历史。 你们应当能够研究这一因素,并表明不平衡的保留来自何处。 您可找到固定的 an体()。 产品-> Analyze更有助于追踪错误的记忆使用。

I assume its something in your player class. Make sure you are releasing all of its properties.

Port your project to ARC (Automatic reference counting). You won t need to deal with releasing and retaining anymore.





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签