开发者

Is there a leak in this copy code?

Is there a leak in this code?

// Move the group
 Group *movedGroup = [[Group alloc] init];
 movedGroup = [[[[GroupList sharedGroupList] groups] objectAtIndex:fromIndex] copy];
 [[GroupList sharedGroupList] deleteGroup:开发者_高级运维fromIndex];
 [[GroupList sharedGroupList] insertGroup:movedGroup atIndex:toIndex];

 // Update the loadedGroupIndex pointer
 if (loadedGroupIndex < fromIndex & loadedGroupIndex >= toIndex) {
  loadedGroupIndex = loadedGroupIndex + 1;
 } else if (loadedGroupIndex > fromIndex & loadedGroupIndex < toIndex) {
  loadedGroupIndex = loadedGroupIndex - 1;
 } else if (loadedGroupIndex == fromIndex) {
  loadedGroupIndex = toIndex;
 }
 [movedGroup release]


The first instantiated Group will leak away. You lost the reference to it (assigning movedGroup = ...) and it's not marked for autorelease. You could reduce those first two lines to:

Group *movedGroup = [[[[GroupList sharedGroupList] groups] objectAtIndex:fromIndex] copy];

and it will do the same, with no leak.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜