serialization

created by Nicopa
(idea) by Nicopa (1.2 y) (print)   ?   (I like it!) Mon May 01 2000 at 6:03:56

In Java, the process which converts an object into a stream of bytes.

The classes ObjectInputStream and ObjectOutputStream provide methods to read/write objects from/to a simple stream (e.g. a file). The state of an object can thus be saved easily, and later restored. The object must be marked as serializable, by implementing the Serializable interface.

(thing) by -brazil- (2.7 y) (print)   ?   (I like it!) Tue May 15 2001 at 8:27:58
There's a pretty devilish memory leak hidden in Java's serialization process that will affect you if you have any such streams that are long-lived (like a permanent network connection or a log file). In order to save space or bandwidth, the ObjectOutputStream keeps references to all objects that have been sent through it. If the same object is sent again, only a short reference to the previous instance is sent, instead of the whole object.

Of course this means that no object ever sent through the stream can be reclaimed by the garbage collection until the stream is closed - a classic memory leak. You can fix it by periodically calling the reset method of the stream, which will remove the references. But if you don't know this, good luck finding the reason for the leak...

(idea) by yossarianc (3.8 wk) (print)   ?   (I like it!) Wed Sep 26 2001 at 16:07:32
Serialization of a method means that calls to the method are handled one at a time. A serialized method cannot have more then one thread operating on it at a time.

Serialization is the enemy of scalability. A serialized method is like a grocery store with only one register open. If there are six people waiting to check out, then it will take close to six times the amount of time for the last one to finish then it would if six registers were open.

However, serialization does have its place. Java's Synchronization offers a way to serialize threads' access to a method.

Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.