[mapguide-internals] Memory leakage in WebTier (Java)

Walt Welton-Lair walt.welton-lair at autodesk.com
Fri Sep 10 17:23:29 EDT 2010


Hi Trevor - I don't think a ticket exists.

-----Original Message-----
From: mapguide-internals-bounces at lists.osgeo.org [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Trevor Wekel
Sent: Friday, September 10, 2010 12:12 PM
To: MapGuide Internals Mail List
Subject: RE: [mapguide-internals] Memory leakage in WebTier (Java)

Has anyone created a ticket for this defect?  I can make the change Walt has suggested below and can help with the investigation of the MgByteReader/MgByteSource refcount if required.  Since this defect causes serious grief the Java Web Extensions, I do consider it a must fix for the 2.2 RC1 build.

Regards,
Trevor

-----Original Message-----
From: mapguide-internals-bounces at lists.osgeo.org [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Walt Welton-Lair
Sent: September 6, 2010 10:54 AM
To: MapGuide Internals Mail List
Subject: RE: [mapguide-internals] Memory leakage in WebTier (Java)

The SAFE_RELEASE call is not correct.  The m_byteSource member in MgByteReader is a smart pointer reference to the underlying MgByteSource.  The MgByteSource is therefore automatically released when the MgByteReader is destroyed.

You wrote: "But when java gc's the bytereader-obj the corresponding c++ obj is also destroyed but the refcnt of the bytesource obj is not decreased."  Did you step through the code and actually observe this?  In the destructor of the unmanaged MgByteReader you should be able to see the smart pointer member variable be destroyed and release its reference to the byte source.

Walt


-----Original Message-----
From: mapguide-internals-bounces at lists.osgeo.org [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Andreas Morf
Sent: Friday, September 03, 2010 2:38 AM
To: 'MapGuide Internals Mail List'
Subject: RE: [mapguide-internals] Memory leakage in WebTier (Java)

Walt,
just implemented your tips and: great, but only one leak remains - and it's not a small one:

MgByteSource::GetReader creates a new MgByteReader obj and increases it's refcnt to 2. But when java gc's the bytereader-obj the
corresponding c++ obj is also destroyed but the refcnt of the bytesource obj is not decreased.

I changed MgByteReader::~MgByteReader() and added a 'SAFE_RELEASE(m_byteSource)' which eliminates the leak but I'm not shure if
that's the correct way to do it.

Andreas

> -----Original Message-----
> From: mapguide-internals-bounces at lists.osgeo.org [mailto:mapguide-internals-bounces at lists.osgeo.org]
> On Behalf Of Walt Welton-Lair
> Sent: Friday, September 03, 2010 12:35 AM
> To: MapGuide Internals Mail List
> Subject: RE: [mapguide-internals] Memory leakage in WebTier (Java)
> 
> I think the fix is simply to update line 2003 in java.cxx with the following:
> 
>   Replaceall(tm, "new $javaclassname(cPtr, $owner)",
> "($javaclassname)ObjectFactory.createObject($module.getClassId(cPtr), cPtr, true)");
> 
> This is analogous to what's in csharp.cxx (see line 1829).
> 
> Walt
> 
> -----Original Message-----
> From: Walt Welton-Lair
> Sent: Thursday, September 02, 2010 6:28 PM
> To: 'MapGuide Internals Mail List'
> Subject: RE: [mapguide-internals] Memory leakage in WebTier (Java)
> 
> We always want our Java (and .NET) proxy wrappers to "own" the wrapped C++ object, and "delete" it
> when the managed class is garbage collected.
> 
> In MapGuide, the meaning of "ownership" via the swigCMemOwn flag is slightly different than what's
> described in the SWIG manual.  Ownership in MG means that when the proxy wrapper is created, the ref
> count of the wrapped C++ class is incremented by one.  When the proxy class is GC'ed, the ref count of
> the C++ class *must* then be decremented again.  The finalizer doesn't explicitly delete the C++
> object; it just calls IDisposable::Release.
> 
> In any case, we'll need to make a small update to the SWIG Java module
> (Oem\SWIGEx\source\Modules\java.cxx) to fix this.
> 
> Walt
> 
> -----Original Message-----
> From: mapguide-internals-bounces at lists.osgeo.org [mailto:mapguide-internals-bounces at lists.osgeo.org]
> On Behalf Of Andreas Morf
> Sent: Thursday, September 02, 2010 2:49 PM
> To: 'MapGuide Internals Mail List'
> Subject: RE: [mapguide-internals] Memory leakage in WebTier (Java)
> 
> Walt,
> I'm aware of this since quite a while but according to SWIG manual
> (http://www.swig.org/Doc1.3/Java.html#memory_management) this is default
> behaviour/semantics of SWIG-Java. I thought that Mg-developers are aware of
> this and continued investigating in C++ code...
> 
> This default behaviour may be overridden with a %newobject annotation at all
> unmananged object delivery methods - silly queston of java programmer: how
> to locate them?
> 
> Why does SWIG-C# handle this different (there is now equivalent swig-c# doc
> about that aspect)?
> 
> Andreas
> 

_______________________________________________
mapguide-internals mailing list
mapguide-internals at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-internals
_______________________________________________
mapguide-internals mailing list
mapguide-internals at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-internals



More information about the mapguide-internals mailing list