gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TextStorage freed when its LayoutManager is removed


From: Fred Kiefer
Subject: Re: TextStorage freed when its LayoutManager is removed
Date: Wed, 24 Mar 2010 09:00:45 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.1.8) Gecko/20100228 SUSE/3.0.3-1.1.1 Thunderbird/3.0.3

No this wasn't caused by the NIB loading fixes, this time it was the
NSTextView change I made :-)
While investigating the NIB problem I noticed that Ink kept on to each
text network it created. I thought that there was no point in fixing NIB
loading when most the same objects get retain just a little bit later
anyway and so I fixed that as well. The basic issue was that the text
storage was retained inside of NSTextView buildUpTextNetwork:, but not
set into the ivar. Correcting this removed the memory leak here. But it
also uncovered places where we weren't careful enough about our text
network. The method replaceTextContainer: was one such place, here the
text storage now needs an extra retain to have it around for the whole
method execution. The same is true in the NSTextContainer method
replaceLayoutManager: and Riccardo pointed me to that in a private mail
yesterday. At the time you reported this bug it was already fixed in
SVN, if we could only be that fast all the time.

The whole text system network is really too complicated. Removing an
object at one level could trigger a release at a completely different
level. It would just be great if somebody with enough time at hand could
have a deep look at all this and see how it could be restructured.

Part of the problem here is the way we program in GNUstep. I try to use
as much explicit memory handling as possible. That is, to avoid auto
released objects. The benefit of this is that objects get freed as soon
as they are no longer needed. But sometimes this might be a little bit
to early, as the recent problems show. With auto release objects these
would stay around until their auto release pool get drained and many
issues could be hidden that way. Still I am reluctant to change my
coding style. I think a library should be as strict as possible with
memory usage. What ever wast can be avoided should be avoided.

Fred

Am 23.03.2010 23:15, schrieb Doug Simons:
> Okay, here's another problem that's apparently been exposed by the recent 
> changes to retains when loading a nib. It appears there is a problem in the 
> way objects retain/release each other in the text system.
> 
> We have an NSSecureTextField in a panel loaded from a nib file. When the 
> panel is displayed, it tries to setup the secure text field which replaces 
> the layout manager with a secure layout manager. But when 
> replaceLayoutManager: calls [textStorage removeLayoutManager: _layoutManager] 
> this results in the textStorage object itself being freed, and it crashes on 
> the next line. I tried to figure out what was going on, but there are a lot 
> of subtle interconnections in the text system, so I'm not sure exactly what 
> isn't being retained that needs to be (or is being released that shouldn't 
> be!).
> 
> Here's what the crash looks like:
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x67848ae6 in objc_msg_lookup () from 
> c:\GNUstep\GNUstep\System\Tools\objc-1.dll
> (gdb) bt
> #0  0x67848ae6 in objc_msg_lookup () from 
> c:\GNUstep\GNUstep\System\Tools\objc-1.dll
> #1  0x63c24e04 in -[NSTextContainer replaceLayoutManager:] (self=0x9de34b0, 
> _cmd=0x63d65b38,
>     aLayoutManager=0x144b890) at NSTextContainer.m:171
> #2  0x63bee87e in -[NSSecureTextView initWithFrame:textContainer:] 
> (self=0x1401ea0,
>     _cmd=0x63db4870, frameRect={origin = {x = 0, y = 0}, size = {width = 0, 
> height = 0}},
>     aTextContainer=0x9de34b0) at NSSecureTextField.m:305
> #3  0x63c9e5f1 in -[NSTextView initWithFrame:] (self=0x1401ea0, 
> _cmd=0x63d8b058, frameRect=
>         {origin = {x = 0, y = 0}, size = {width = 0, height = 0}}) at 
> NSTextView.m:744
> #4  0x63c3aa9c in -[NSView init] (self=0x1401ea0, _cmd=0x63d65aa8) at 
> NSView.m:566
> #5  0x63bee378 in -[NSSecureTextFieldCell setUpFieldEditorAttributes:] 
> (self=0x15a35a0,
>     _cmd=0x63d7df98, textObject=0x1290ee0) at NSSecureTextField.m:209
> #6  0x63c2649e in -[NSTextField selectText:] (self=0x994d9d0, 
> _cmd=0x63d7e070, sender=0x994d9d0)
>     at NSTextField.m:181
> #7  0x63c26e17 in -[NSTextField becomeFirstResponder] (self=0x994d9d0, 
> _cmd=0x63d91b70)
>     at NSTextField.m:431
> #8  0x63c53285 in -[NSWindow makeFirstResponder:] (self=0x16594c0, 
> _cmd=0x585240,
>     aResponder=0x994d9d0) at NSWindow.m:3176





reply via email to

[Prev in Thread] Current Thread [Next in Thread]