Mapscript ,Mono, Apache and Linux : a great story

Tamas Szekeres szekerest at GMAIL.COM
Fri Jun 16 09:57:18 EDT 2006


> All the layerObj object i use  in my program are déclared in the mapfile so
> i don't need to create layerObj from scratch using the constructor.
> When you say that if a layerObj reference with a previously released native
> memory segment, it may causing the error, what are the consequences for my
> code ? Using the Dispose method is there the solution to avoid this problem
> ?

Most of the mapscript classes implement the IDisposable interface
since they maintain unmanaged memory segments. It is a good practice
to explicitly call Dispose (or by the using directive) if a newly
created object is not needed any more. However you might want to
maintain the mapObj reference for a longer period and the disposing
will occur during the program destruction.
Getting an existing object reference (eg. as returned by
GetLayerByName) does not create a new object, so calling dispose is
not needed.
All of the objects internally maintain a flag indicating if it should
free the internal memory during the finalization. So calling Dispose
in the previous case might also not cause any problems.

So you may not have to take care much of these issues the existing
problems may dedicated to unproper handling of this reference and
considered to be fixed. However it is not so easy to locate the reason
of the problem since the crash will be slipped out on a subsequent
finalization or the program termination.

> How can i get CVS code ?

using Tortoise CVS is fairly straightforward.

> Why this code works well under windows and scratches under linux ?

You may use different frameworks and CRT libraries. The problem may
still exists but not manifested.


More information about the mapserver-users mailing list