Re: NSTableView and Java
Re: NSTableView and Java
- Subject: Re: NSTableView and Java
- From: Jeremy Bower <email@hidden>
- Date: Sun, 12 May 2002 16:06:03 -0400
On Sunday, May 12, 2002, at 02:01 PM, Bryan Zarnett wrote:
I'm having a hell of a time debugging a problem with NSTableView in
Java.
The view comes up with the data from my data source. I can click on it
a few
times, resize it once or twice and then I get the following exception:
2002-05-12 13:54:28.547 CocoaTableTest[2163]
java/lang/NullPointerException
Stack Trace:
java.lang.NullPointerException
ObjCJava FATAL:
jobjc_lookupObjCObject(): returning garbage collected java ref for objc
object of class SomeDataSource
ObjCJava Exit
This means your SomeDataSource object has been garbage collected by the
Java VM. Objects can be garbage collected only happens when they're not
reachable through strong references. In this case, Cocoa has a weak
reference to an object that has been GC'd.
It's very annoying since there is very little code:
// This is in my window controller
SomeDataSource someDataSource = new SomeDataSource();
tableView.setDataSource(someDataSource);
The problem is that the table view uses a weak reference to hold your
SomeDataSource object. If your only strong reference is a local variable
(shown above), then the object will be eligible for garbage collection
as soon as the method exists.
In Obj-C, weak references prevents memory leaks -- a good thing. In
Java, the same behavior causes objects to be released while they're
still in use -- a bad thing. The solution is to hold a reference to
SomeDataSource (perhaps in the WindowController) as long as the table is
in use.
This is a very annoying problem, but not that difficult to solve.
Hopefully, Apple is looking at ways to fix this issue.
Jeremy
--
Jeremy Bower
mailto:email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.