On Mar 4, 2007, at 9:33 AM, Ben Hood wrote:
> Hi all,
>
> I have a question about maintaining object references in the
> JavaSerializer class (see snippet below).
>
> This seems to maintain a reference to every object it serializes.
>
> In a streaming scenario where you want to stream mass data, this is
> causing memory consumption issues.
>
> To work around this I suclassed JavaSerializer and removed the
> reference maintenance with the writeObject() method.
>
> I should emphasize that this is only a workaround, as:
>
> - I had to copy a lot of the fields and code form the super class
> because most of the stuff I needed isn't publicly visible.
>
> - This ignores the reference maintenance code, which may be
> functionally wrong and have other adverse effects.
>
> I was wondering if there is any scope to change the API of the
> JavaSerializer to cater for this issue?
>
> Instead of completely bypassing the reference maintenance, maybe one
> could set a limit of the size of the hash map?
Making a change would be fairly straightforward. It would probably
be best to change HessianInput/HessianOutput, not the serializers.
We'd also need to add an update to the spec, because technically the
receiving end is required to keep references to all the objects just
in case there's a back reference needed. So we'd need to add a
"streaming hessian" sub-protocol which removed the back references,
just like we have the "micro-hessian" which skips doubles.
-- Scott
>
> Thanks,
>
> Ben
>
> -----
>
> public void writeObject(Object obj, AbstractHessianOutput out)
> throws IOException
> {
>
> // ignore reference maintainance code .....
>
> if (out.addRef(obj))
> return;
>
> Class cl = obj.getClass();
>
> try {
> if (_writeReplace != null) {
> Object repl = _writeReplace.invoke(obj, new Object[0]);
>
> out.removeRef(obj);
>
> out.writeObject(repl);
>
> out.replaceRef(repl, obj);
>
> return;
> }
> } catch (Exception e) {
> }
>
> int ref = out.writeObjectBegin(cl.getName());
>
> if (ref < 0) {
> writeObject10(obj, out);
> }
> else {
> if (ref == 0)
> writeDefinition20(out);
>
> writeInstance(obj, out);
> }
> }
>
>
> _______________________________________________
> hessian-interest mailing list
> [email protected]
> http://maillist.caucho.com/mailman/listinfo/hessian-interest
_______________________________________________
hessian-interest mailing list
[email protected]
http://maillist.caucho.com/mailman/listinfo/hessian-interest