Is there a way in Xcode 4 to find objects which have not been dealloced?
In my app, I have random objects floating around in my view which I had THOUGHT I deleted through [NSMutableArray replaceObjectAtIndex:index withObject:newObject] BUT it turns out tha开发者_开发知识库t after I made alpha = 0.5, those replaced old objects were still there. Since I am using the new xcode 4 with ARC, I can't check whether those objects have failed to dealloc or something. So, is there any technique or command in xcode 4 (yes the new one) that can help with this sorta debugging?
Also, in xcode 4, will removing an object from view delete it? I used [object.view removeFromSuperView] to get them out of the view, but I have no idea whether they are still existing somewhere else, causing memory leaks.
The best way to get help in that area is using Instruments (specifically the allocations tool) in order to 'debug' which objects are still alive, and what their call-stack is. It takes some fiddling around, but it is a powerful set of tools.
I agree that using Instruments(/Developer/Applications/Instruments) is the way to go, but you can also set breakpoints in your code. See the 'Debugging and Analyzing Your Code' section in the 'Xcode 4 Transition Guide' I would also suggest iterating through the super view's subview using the view's property subviews, like so.
for ( UIView *view in self.view.subviews) {
// Check your objects here.
}
As to memory management, if you use new, alloc, mutablecopy or copy you own it and need to take care of the object's memory allocation and deallocation. You can either use auto release or release it in your dealloc method. The uiview method removeFromSuperView will release your object.
Hope that helps, fragilecat
精彩评论