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?

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

Reply via email to