[geos-devel] Question about geos::io::Unload::Release()

strk at refractions.net strk at refractions.net
Sat Mar 11 14:19:39 EST 2006


Geometry::INTERNAL_GEOMETRY_FACTORY should really
be a singleton, probably GeometryFactory::getInternalInstance()

Unload class has been introduced to procrastinate these kind
of cleanups :) Your assumption is correct, should only be
called as *last* action of a *debuggin* module, no need
to be called by user code, it's just there to avoid false leaks
reported by memory checkers.

--strk;

On Sat, Mar 11, 2006 at 08:14:35PM +0100, Mateusz Å?oskot wrote:
> Hi,
> 
> Could anyone explain me the idea behind Unload class and its Release 
> function?
> I'm also interested in the idea behind this static member:
> const GeometryFactory* Geometry::INTERNAL_GEOMETRY_FACTORY;
> 
> What semantic exactly those entities represent?
> What is the lifetime of Geometry::INTERNAL_GEOMETRY_FACTORY;
> 
> IMHO geos::io::Unload::Release() may confuse users and they can use it 
> in wrong way pretty easily.
> 
> Let's consider small example:
> 
> Here is a file test.cpp and in that file I have two
> functions: foo and bar.
> Inside each function I have some automatic objects: local 
> GeometryFactory and PrecisionModel and I also create new geometries.
> Nothing comes in and goes out to/from those functions.
> 
> // File: test.cpp
> 
> #include <geos/unload.h>
> #include <geos/geom/Coordinate.h>
> #include <geos/geom/Envelope.h>
> #include <geos/geom/GeometryFactory.h>
> #include <geos/geom/Point.h>
> #include <geos/geom/PrecisionModel.h>
> 
> void run()
> {
>    foo();
>    bar(); <--- BANG!
> }
> 
> void foo()
> {
>     geos::geom::PrecisionModel pm(1);
>     geos::geom::GeometryFactory gf(&pm, 0);
> 
>     geos::geom::Coordinate c1(5, 6);
>     geos::geom::Point* p1 = gf.createPoint(c1);
>     geos::geom::Geometry* e1 = p1->getEnvelope();
> 
>     // Do something else
>     // ...
> 
>     // MEMORY CLEAN UP
>     delete e1;
>     delete p1;
>     geos::io::Unload::Release(); // <----------- HERE IS OK
> }
> 
> void bar()
> {
>     geos::geom::PrecisionModel pm(1);
>     geos::geom::GeometryFactory gf(&pm, 0);
> 
>     geos::geom::Coordinate c1(5, 6);
>     geos::geom::Point* p1 = gf.createPoint(c1);
>     geos::geom::Geometry* e1 = p1->getEnvelope();
> 
>     // Do something else
>     // ...
> 
>     // MEMORY CLEAN UP
>     delete e1;
>     delete p1;
>     geos::io::Unload::Release(); // <----------- BANG! BANG!
> }
> 
> Simply, it seems Unload::Release() can not be called twice in the same 
> module/program. Is this correct assumption and behaviour?
> 
> It's not clear for my why to not to hide clean up operations inside 
> destructors or why not to make some of "long living single objects" as 
> singletons that are safe regarding memory management?
> If relations are more complex and the number of global objects that we 
> need to release is not known, then I'd suggest to provide a kind of 
> arena idiom or smart pointer to get garbage collected properly.
> 
> Please, review current situation.
> 
> Cheers
> -- 
> Mateusz Łoskot
> http://mateusz.loskot.net
> _______________________________________________
> geos-devel mailing list
> geos-devel at geos.refractions.net
> http://geos.refractions.net/mailman/listinfo/geos-devel

-- 
----------------------------------------------------------------------
State-collected Geographic Data is public property !
Reject the INSPIRE directive.
Sign the petition: http://petition.publicgeodata.org



More information about the geos-devel mailing list