[mapguide-internals] Memory leakage in WebTier (Java)
Andreas Morf
a.morf at fkl.ch
Fri Sep 3 02:38:06 EDT 2010
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
>
More information about the mapguide-internals
mailing list