Interesting... Your fix looks right to me... And in fact this is a serious memory leak, so the fix is much appreciated.

I believe that the reason _tupleList is null is that the instance
of VersionAttribute is added to the workspace before setContainer()
is called to set the container. Then when setContainer() is called,
the object should get removed from the workspace, since the workspace
only contains top-level objects. setContainer() is called in the constructor
of the base class, probably NamedObj, so the fields of the derived
class have not been constructed yet.

I've implemented your fix in our development tree...

Edward



At 11:15 AM 1/29/2004 +0100, Richard van der Laan wrote:
Hi there,

I discovered a problem related to the VersionAttribute class while
integrating the ptolemy kernel in one of our own applications. Our
application creates a default workspace that is reused over the life-cycle
of many executed models. Models are manually parsed from a MoML file and
added to the workspace as seperate composite entities. After the model has
been executed it is removed from the workspace. By printing a workspace
directory list after the remove operation I discovered that the
VersionAttribute that is contained by the model is not removed from the
workspace. I don't know if Vergil creates a single workspace that is
reused for every new model, but in our application this eventually leads
to a out of memory exception.

The workspace remove operation discards all contained named objects by
calling remove on the internal workspace directory list. However this
operation fails for a VersionAttribute object. By analysing the equals
method of this class I discovered that equals fails for a comparison
between two identical object references:

    public boolean equals(Object obj) {
        // If the _tupleList is null, then we are not fully constructed.
        // I see no choice but to return false.
        if (_tupleList == null) {
--->        return false;
        }
        if (obj instanceof VersionAttribute) {
            return (compareTo(obj) == 0);
        }
        return false;
    }

Somehow the tupleList attribute does not exist during this call. I should
mention that the VersionAttribute object was created by the MoMl parser
and setExpression was applied under normal conditions. Therefore I cannot
explain why tupleList is null. Maybe there is a clone method involved.
However if it is correct that the tupleList attribute can be null under
these conditions, the implemention of the equals method should be modified
by calling equals on it's parent:

    public boolean equals(Object obj) {
        if (_tupleList == null) {
--->         return super.equals(obj);
        }

        if (obj instanceof VersionAttribute) {
            return (compareTo(obj) == 0);
        }
        return false;
    }

This provides a working solution to our problem. However the fact that
tupleList can be null when parsed from a MoML file doesn't make any sense
to me.

Kind regards,

Richard van der Laan / [L]uminis
Email : [EMAIL PROTECTED]
TheWeb: http://www.luminis.nl

----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

------------ Edward A. Lee, Professor 518 Cory Hall, UC Berkeley, Berkeley, CA 94720 phone: 510-642-0455, fax: 510-642-2739 [EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal


---------------------------------------------------------------------------- Posted to the ptolemy-hackers mailing list. Please send administrative mail for this list to: [EMAIL PROTECTED]

Reply via email to