Garbage Collector in JC 2.2
Help: I am trying to understand how a Passive Garbage Collector (GC) implementation works in Java Card v2.2. As I understand it, Java Card vendors have the option to implement Automatic GC or a Passive GC under version 2.2 or higher.
My question is as follows:
What if object X no longer used, and was instantiate during the install() process:
With Automatic GC: the GC would automatically reclaim memory after the process() method finish executing. If object X has no other references. Also, any other objects without any references would be reclaimed as well.
With Passive GC: In the process() method the developer must call requestObjectDelete(), and before the next APDU request, the JCRE would reclaim memory. Is this right?
What happens requestObjectDelete() is called on an object that still has references? Does it still reclaim it? In either Passive or Automatic GC?
Do any vendors supporting Automatic GC? How about Java Card version 2.2.2?
Thank you for any help
Maguar
[1035 byte] By [
mag-guara] at [2007-11-26 17:50:59]

# 1
You have a lots of questions there. I try to comment on one:
> What if object X no longer used, and was instantiate during the install() process:
The only reason I see why you would want to instantiate objects in the install() method, is if you want to evaluate the global bArray (e.g. AID, length ...). If you do not copy this values to a instance object (e.g. a byte array), this values are not referenced anymore after you return from this method. The GC collects this garbage on a) JCRE triggers the GC b) requestObjectDeletion() is called.
I am sure mkdata can answer all your questions (wink). Until then see his posts in this topic about the GC:
http://forum.java.sun.com/thread.jspa?threadID=5114048&messageID=9398276
# 2
> What happens requestObjectDelete() is called on an object that still has references?
Until now I haven't seen a method called "requestObjectDelete()" (and Google, too).
Are you probably referring to the static method JCSystem.requestObjectDeletion() ?
This method can not be called "on an object". It only allows to explicitly invoking the GC for freeing the memory allocated by objects that can not be accessed anymore.
This solves the problem that current JavaCards are not multi-threaded. Therefore the GC can not be started in background as it does in the J2SE environment.
By calling JCSystem.requestObjectDeletion() a JavaCard applet "voluntary" gives away CPU time to the GC. In single threaded environments this means that the caller (the JavaCard applet) is halted until the GC has finished its work.
Jan
# 3
Thank you, so would it be right to state (maybe too simplistic):
Automatic GC: works automatically before receiving another APDU request, on all unreference objects.
Passive GC requires a call to JCSystem.requestObjectDeletion(), otherwise no memory reclaim occurs. Is this right?
Thanks in advance
Maguar