Java: Serialization: How to store only a reference, not the content -
i'm creating undo-redo mechanism. achieve this, i'm using serialization. recording current state writing bytearrayoutputstream
, using objectoutputstream
, putting byte[]
arraylist.
but problem that, of classes holding reference/pointer bufferedimage
. don't want serialize because of size (and doesn't implement serializable
). reason why don't want write never change. but different image each instance of class, static
keyword isn't solution.
my attempt solve:
public transient bufferedimage img;
this causes objectoutputstream
not serialize bufferedimage, won't store reference well. after deserializing, null
.
so, in short, want keep reference object, not object itself. means that, after deserialazing able use bufferedimage (because of isn't removed garbage collector).
many thanks.
ok, simple enough, keep map<string, bufferedimage>
of images somewhere in application, let each of classes serialize key image. , in readresolve()
method, image map.
Comments
Post a Comment