Skip navigation.
 
mlRe: removeFromSuperview crash - please help
FROM : Matt Neuburg
DATE : Sat Nov 06 21:49:36 2004

On Sat, 6 Nov 2004 10:46:54 -0800 (PST), Keith Blount
<<email_removed>> said:
>it seems that if I retain the subview before
>callling removeFromSuperview (or if I never release it
>after adding it using addSubview: in the first place),
>it will never be released. But if I release everything
>in the proper place (ie. release the NoteCard after it
>is added as a subview using addSubview:, relying on
>its parent to retain it), then on calling
>removeFromSuperview, release will be called too many
>times and cause the app to crash.


(1) I always all setNeedsDisplay:NO on a view before I remove it from the
superview. Call it superstition if you like.

(2) I add and remove things from superviews like crazy and I don't crash. I
even call [self removeFromSuperview]. So I don't see what you're doing
wrong. I presume that that is because what you are doing wrong is somewhere
else, not in the code you showed. :) What happens if you retain the
superview, autorelease it, and remove it from the superview? My idea here is
that you will thus postpone the release until after the event is over.
However, that's just a guess. The real problem is that you say you crash but
you don't say why. I'm wondering whether it's because something *else*
besides the superview has a reference to the subview and tries to access it
after it has been released. m.

--
matt neuburg, phd = <email_removed>, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>

Related mailsAuthorDate
mlremoveFromSuperview crash - please help Keith Blount Nov 6, 19:46
mlRe: removeFromSuperview crash - please help Jacob Lukas Nov 6, 21:33
mlRe: removeFromSuperview crash - please help Keith Blount Nov 6, 21:48
mlRe: removeFromSuperview crash - please help Matt Neuburg Nov 6, 21:49
mlRe: removeFromSuperview crash - please help (solved) Keith Blount Nov 7, 00:40