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.
精彩评论