[java-gnome-hackers] java-gnome memory management issues
Brought to you by:
afcowie
|
From: Vreixo F. <met...@ya...> - 2008-08-26 11:18:23
|
Hi Andrew!
I've started just now to review the Value issue, and that lead me to
find another memory management problem.
Entity subclasses (Context, Pattern, Surface) implement abstract
Proxy.release() method, and they free there underlying C resources.
However, when the Entity is garbage collected, the release() method is
never called.
The problem is the wrong design of that part. Proxy defines and abstract
release() method, but its finalize() is not responsible for calling it.
Instead, Proxy subclasses override the finalize() method with something
like this:
protected void finalize() {
release();
super.finalize();
}
Obviously, if release() is defined in Proxy, a better design would be
having this piece of code there.
However, Boxeds are a problem, as they're release only if owner == true.
I think, however, that the code
if (owner) {
release();
owner = false;
}
super.finalize();
present in Boxed.finalize() should be really present in Boxed.release(),
and define an abstract method in Boxed (free(), for example) that each
Boxed subclass should implement.
On the other side, I will also create a Proxy superclass (Pointer,
maybe?) where the release() function will be defined, leaving on Proxy
only the responsibility of handling the Proxy map.
Values, for example, will inherit from Pointer instead of Proxy. I think
that Boxeds may also inherit from Pointer instead of Proxy, but I need
to think a bit more about it... we will see.
Cheers
Vreixo
|