|
Garbage Collection IssuesThere are some points to be considered when looking at garbage collection in Java with Chameleon objects. It is not guaranteed that the Java interpreter will invoke the finalize() method of any given Java object. This represents something of a design issue for Chameleon's java classes. We overcame it by using the following approach. The Table class and the ChameleonDateTime class have release() methods which can be explicitly called if the finalize() method is not called. The structure of the classes was designed such that the release() method is normally invoked automatically without you needing to think about it. Except for some special cases which are described next, this is not an issue you need to worry about. The release() method can be called multiple times without any problems. However, once released, other methods on the object should not be called. Parsing with StubcodeNo problem. When parsing a message with the stubcode interface to Chameleon, the generated <prefix>Engine object in the parseMessage method has a try...finally clause which ensures that the release method is called on the message object after the on<Message Name>Message has returned. Generating MessagesNo problem as long as no exceptions are thrown. When generating messages, the generateMessage method will call release on the underlying table. As a consequence, it results in an error if you try and call generateMessage twice on the same message object. The only thing you need to be aware of is that if an exception is thrown in the code you use to populate the message object, and unless you explicitly put a try...finally block to ensure that the release() method is called, there is a small risk that it will not be called. Usually the java interpreter will invoke the finalize() method which will fix the situation. You will not have to worry about this issue for the most part. Having an exception thrown in your message generation code is usually an indication of a bug in your own code that you need to fix. Parsing with the Dynamic InterfaceBe careful. When parsing messages with the dynamic interface, it's important that you invoke the release() method on the Table object. ChameleonDateTime ObjectsFor the most part it's not necessary to worry about calling the release() method on ChameleonDateTime objects. Generally the instances of these objects are owned by the Table objects that you are manipulating. In the case of the static class method, now() refers to a singleton object so there are no problems with it. The only time you would have to worry about calling release() on this object is if you created a standalone instance of the class. |