Re: NSTextView problem
Re: NSTextView problem
- Subject: Re: NSTextView problem
- From: Greg Herlihy <email@hidden>
- Date: Sat, 04 Mar 2006 11:24:29 -0800
- Thread-topic: NSTextView problem
The Text System documentation recommends inserting text into the
NSTextStorage object directly, and to bypass the NSTextView routines that
deal with text from user input. Also, I would append, rather than insert the
text. Finally I would set the insertion point to the very end of the text
after the insertion.
Something along these lines:
- (void)addStringToLog:(NSString *) msg
{
[[[logText textStorage] mutableString] appendString:msg];
NSRange range = NSMakeRange([[logText textStorage] length], 0);
[logText scrollRangeToVisible:range];
}
But it sounds like the primary problem is simply allowing too much text to
accumulate in the NSTextView to start with. The NSTextView is probably
spending so much of its time calculating the word wrapping, that the machine
effectively appears to hang. And although NSTextView can handle large
amounts of text, it cannot handle unlimited amounts of text. In particular a
program must be careful never to let any of its resource allocation patterns
- including caching and logging - to continue without any upper bound having
been set. And considering that a literary novel is approximately one
megabyte worth of data, I would suggest capping the amount of text in the
NSTextView at, say, five megabytes of text (if even that many) and either
delete or write entries to disk beyond that point.
Greg
On 3/3/06 6:25 PM, "Peter" <email@hidden> wrote:
> I am doing a simple log window of messages similar to terminal
> application. Messages are display row by row on a NSTextView and when
> it reach to bottom of the window, it should scroll up, make way for
> the newer incoming messages.
>
> However after running for a while, after displaying thousands of
> line, it stops and the infamous spinning cursor cames out. The whole
> application freeze and I can only force quit. I manage to trace down
> the culprit, "scrollRangeToVisible" NSText method. When the statement
> is commented/remark then recompile for testing, the problem
> disappears. By commenting out the statement, however the NSTextView
> stops scrolling upwards when messages hit bottom of the view.
>
> I been thinking doing a custom NSView to replace NSTextView but it
> looks like a lot of work and may not able to do some of the things
> NSTextView do (such as text selection, clipboard copy).
>
> I hope somebody can help me with this.
>
> Is the way around this problem ? Why does it crash it the first place ?
>
>
> // logText is the NSTextView
> //
> - (void) addStringToLog:(NSString *) msg
> {
> NSRange endOfText;
>
> endOfText.location = [[logText string] length];
> endOfText.length = 0;
> [logText replaceCharactersInRange: endOfText withString: msg];
> [logText scrollRangeToVisible: endOfText]; // "culprit"
> }
>
>
> Thanks.
>
> Peter
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden