 |
 |
NSTextView problems..
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
I have an NSTextView that leaks like crazy. I'm not sure if it's my fault so here's some code:
NSTextView view; //the outlet from IB.
//contructor goes here and it creates the class
//that puts things into the NSTextView
//my method for inserting text
public void appendText(String text) {
if (view != null && text != null)
view.insertText(text);
}
here's some of the errors:
*** _NSAutoreleaseNoPool(): Object 0x8127f0 of class NSCFDictionary autoreleased with no pool in place - just leaking
*** _NSAutoreleaseNoPool(): Object 0x811be0 of class NSCFString autoreleased with no pool in place - just leaking
*** _NSAutoreleaseNoPool(): Object 0x813410 of class NSConcreteValue autoreleased with no pool in place - just leaking
*** _NSAutoreleaseNoPool(): Object 0x811b60 of class NSCFDictionary autoreleased with no pool in place - just leaking
*** _NSAutoreleaseNoPool(): Object 0x815230 of class NSCFString autoreleased with no pool in place - just leaking
I had to leave it Editable in order to get anything in the NSTextView at all but it should only be selectable. Think of it as an error-log display or something. Letting the user directly edit it isn't what I'm going for. I need to be able to append text and colors/styles would be a plus. I've managed to get colors working(sorta) but no matter what I try I can't shake the leak.
well, thanks in advance!
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
I still haven't found a solution. I've read through the related docs several times now and still can't figure out what to call and when. It looks as though I should be calling view.replaceCharactersInRange(NSRange, String) to insert my text but after trying that I still get the same leaks.
This isn't fun. If I could forget the fact that it leaks like crazy I could move on to other parts of the program but since this is the center of it all I'm kind of stuck.
any help would be great! 
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
So, instead of using IB to create my NSTextView and NSScrollView I've done it myself. After reading the docs again, I realized if it's editable you can use insertText(String) but if you setEditable(false) you can't...
now that I setEditable(false), I use..
Code:
public void appendText(String msg) {
NSRange range = new NSRange(textview.string().length(),0);
//'ask' permission
if (textview.shouldChangeTextInRange(range, msg+"\n")) {
textview.textStorage().beginEditing(); //tell the storage we want to begin
textview.replaceCharactersInRange(range, msg+"\n"); //make the change
textview.textStorage().endEditing(); //tell the storage we're done
textview.didChangeText(); //tell the NSTextView to update the display
}
}
problem is, I still can't shake the leak. Any ideas? Well, off to hunt some more, I guess.
thanks in advance, again.
[fixed code]
[This message has been edited by IamBob (edited 12-16-2000).]
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Dec 2000
Status:
Offline
|
|
I was also annoyed at not being able to insertText on a TextView that wasn't editable. I got around it by making it editable just before I called insertText, and then turning editable back off.
Anyhow, when exactly are you getting these errors? It sounds more like the problem is in your controller class.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
I get the leaks when my appendText() method gets called. I'm supposed to have a controller class? uh oh!
hmm..your idea of making it editable right before an insertText() call sounds good. I suppose I could go that route but I have to work magic on the text anyway(colors, styles, fonts, etc) so either way I guess.
I guess I'll keep looking. thanks for the ideas!
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
Okay, I could've edited the above message but oh well...
I'm extremely new to this API and way of working. I've always hand-coded my GUIs in Java. So, if I seem dense that's probably why(either that or I am dense).
It didn't register until just now....you've actually managed to get an NSTextView working? If there's anyway you can email me an example..please!? It doesn't even have to do anything..an outlet for me to work with that doesn't eat up memory would just kick@$$!
Well, if so: the_name_thief@yahoo.com
even if you don't at least I know it can be done! thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
I just noticed...
You're the one that thinks Nicer should be part of Apple's Process Viewer? see versiontracker.
...can I take that as a compliment? 
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Dec 2000
Status:
Offline
|
|
Well... it's sort of a compliament. I mean, Nicer's a great idea, but at the same time it seems silly that it has to be a separate application. I just think Apple ought to steal the idea from you. (-:
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
but how many people would keep Process Viewer open all the time? I can keep Nicer running 24/7 and not have to worry that it's eating serious cycles and mem. I'd rather see apps become more specific than see them start to bloat...I dunno, maybe it's just me.
anyway...
thanks for the email! Maybe I should just learn Obj-C and get it over with.
You might try the Obj-C equiv of my last appendText() method...I dunno. looks good though.
Well, I'm off to toy with it some more, I guess.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
Well, I finally figured out it isn't leaking from my appendText() method. I started a new project and 3 minutes later I was inserting text...no problem.
So, I guess it's time to go through and pick apart my code and test until me eyes bleed! I was sooo hoping it would be something simple that I overlooked in IB or something...damn!
thanks for the help! 
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
Now, after messing around some more I think I've decided that it is in the appendText method. This time I'm not changing my mind.
I was messing with my 3 minute project and it turned into a 10 minute project that had a Thread that tried to appendText(). Well, when it wasn't threaded it worked flawlessly. Add a Thread and there's trouble. So, I sent Apple a bug report.
If someone wants to figure out how to get text into an NSTextView from a different Java Thread...you can make me feel and look really stupid. :-)
l8r.
|
|
|
| |
|
|
|
 |
|
 |
|
jroepcke
|
|
Originally posted by IamBob:
*** _NSAutoreleaseNoPool(): Object 0x8127f0 of class NSCFDictionary autoreleased with no pool in place - just leaking
That error message generally means something is happening in a Java thread that doesn't have an NSAutoreleasePool set up.
The Java Cocoa objects (Foundation/AppKit) are bridged to Objective-C instances of the same class. Cocoa objects need to be in an NSAutoreleasePool so that they won't be released by the Obj-C side of the bridge before the Java side is done with them.
At the beginning of the thread, instanciate an NSAutoreleasePool and push it. You'll get an int as the return value. Keep that int for the duration of the thread. Just before the thread ends, pop the NSAutoreleasePool -- you'll need to pass that int in.
If you do that, those leak messages will go away and java garbage collection will work as you expect.
If you aren't explicitly creating and starting your own threads, it's something in AppKit. There's probably a simple solution in that case too, but I'm not sure exactly where the push/pop statements _should_ go in that case.
The OmniGroup mailing lists are the best place to get help. I highly recommend macosx-dev.
http://www.omnigroup.com/community/d...sts/macosx-dev
Objective-C is easy, and can be fun to program in. Apple has a book called "Object Oriented Programming and the Objective-C Language" that I'm convinced can teach any experienced programmer Objective-C in a few hours.
You can get it hardcopy from fatbrain, or in PDF/HTML format on the Apple Developer Connection web site. It's probably in /Developer/Documentation/Cocoa/Reference as well in OSX.
Jim
[This message has been edited by jroepcke (edited 12-23-2000).]
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
Great! That's exactly what I was looking for.
The thread is one I had to create and not some unknown thread running amuck. I needed to loop to get data for my display and doing that in the main thread would hault the whole thing.
I'll try the push/pop thing...
thanks!!
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
5 minutes after my last post it was working perfectly.
I suppose I should've payed a little more attention. I could've just looked up NSAutoReleasePool in the JavaBrowser. No more leaks!!! wooo!
Thanks a million!
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|