mapscript jvm crash on removeLayer

listuser HH listuser at HERZSYS.DE
Fri Sep 8 07:05:50 PDT 2006


Hi,

yes I mean the temporary  layer. I try to give a little example at the
end. - there are other ways to do it.

I think this defined deleting of objects avoid the crashes when done in
the correct order. I had crashes before. After some researching I saw
that objects get deleted in a not ordered way (because of the way the
garbage collection works) which . I can't remember the exact process and
result of this at the moment but it was definitely the garbage
collection which caused the crash.

Regards
Norbert

A little example:

layerObj tmpLayer = null;
layerObj orgLayer = null;
mapObj tmpMap     = null

tmpMap = map.cloneMap();
tmpLayer = new layerObj(tmpMap);

tmpLayer.setStatus(1);
tmpLayer.setName("MS");
tmpLayer.setType(MS_LAYER_TYPE.MS_LAYER_POINT);

classObj cl = new classObj(tmpLayer);

styleObj style = new styleObj(cl);
colorObj tmpColor = new colorObj(255, 0, 0, 0);
style.setColor(tmpColor);

labelObj la = new labelObj();
la.setType(MS_FONT_TYPE.MS_BITMAP);
la.setFont("small");
               
cl.setLabel(la);

Iterator<MyPoint> pointIterator = pointList.iterator();
while (pointIterator.hasNext()) {
    shapeObj shape = new shapeObj(MS_SHAPE_TYPE.MS_SHAPE_POINT.swigValue());
    lineObj line = new lineObj();
    MyPoint myPoint = pointIterator.next();
    int status = line.add(new pointObj(myPoint.getX(), myPoint.getY(), 0));
    if (status == MS_RETURN_VALUE.MS_FAILURE.swigValue()) error = true;
    if (shape.add(line) == MS_RETURN_VALUE.MS_FAILURE.swigValue()) error
= true;
    shape.setText(myPoint.getName());
    if (tmpLayer.addFeature(shape) ==
MS_RETURN_VALUE.MS_FAILURE.swigValue()) error = true;
}

tmpColor.delete();
la.delete();
style.delete();
cl.delete();
orgLayer.delete();
tmpLayer.delete();

Mike Talbutt schrieb:
> Thanks for your answer Norbert, 
>
> Can you explain to me what exactly you are doing in step 3 ?, I assume
> you mean insert the temporary layer that is currently in your temporary
> mapobj into the main mapobj I am using ?, if this is the case how do you
> do this in mapscript ?.
>
> Also where and how would I remove the original layer ?
>
> Would this solution stop the jvm crashing when calling removelayer ?
>
> -----Original Message-----
> From: listuser HH [mailto:listuser at herzsys.de] 
> Sent: 08 September 2006 12:37
> To: Mike Talbutt
> Cc: MAPSERVER-USERS at LISTS.UMN.EDU
> Subject: Re: [UMN_MAPSERVER-USERS] mapscript jvm crash on removeLayer
>
>
> Hi,
>
> you can try the following:
>
> 1. make a temporary mapObj (new..  or map.clone)
> 2. make a temporary layer and add the annotations
> 3. insert the layer with annotations in the mapObj
> 4. do something (e.g. draw)
> 5. call delete on this layer
> 6. call delete on the temp mapObj
>
> Regards
> Norbert
>
> mikiet schrieb:
>   
>> Hi,
>>
>> I am using java mapscript in an application. I have the requirement to
>>     
>
>   
>> add annotations to an inline layer, and remove annotations from an 
>> inline layer.
>>
>> I beleive removing annotations from an inline layer is not availble in
>>     
>
>   
>> mapscript so as a work around I wanted to create a new layer with all 
>> the features from my inline layer except the one I wanted to remove, 
>> then remove the old layer (Hope that makes sense !).
>>
>> Unfortunatly when I try and remove my old layer from the map the jvm 
>> crashes taking down the tomcat process.
>>
>> >From the entry 'Java VM Crashes using the Mapscript API' I can see a 
>>     
>>> few
>>>       
>> people have had simillar problems and its being put down to a garbage 
>> collection problems in the jvm. The post states you should call the 
>> delete method on a classObj when it is no longer used, I have tried 
>> this but its not got rid of the problem. Can anyone point me in the 
>> right direction please
>>
>> My code is below...
>>
>> 		layerObj annLayer =
>>     
> mapobject.getLayerByName(sLayerName);
>   
>> 		layerObj newannLayer = new layerObj(mapobject);
>> 	        int featureCounter = 0;
>> 	        while (featureCounter < annLayer.getNumFeatures()){
>> 	            shapeObj shape2 = annLayer.getFeature(
>>     
> featureCounter ,-1); 
>   
>> 	        	if (shape2.getValue(1).equals(sName)){
>> 	        		System.out.println("retreived shape
>>     
> index - " + 
>   
>> shape2.getIndex());
>> 	                        System.out.println("retreived shape - "
>>     
> + 
>   
>> shape2.getValue(1));
>> 	        	}
>> 	        	else{
>> 	        		System.out.println("adding feature to
>>     
> new layer " + 
>   
>> shape2.getValue(1));
>> 	        		newannLayer.addFeature(shape2);
>> 	        	}
>> 	        	featureCounter++;
>> 	        }
>> 	        annLayer.getClass(0).getStyle(0).delete();
>> 	        annLayer.getClass(0).delete();
>> 	        annLayer.delete();
>> 	        mapobject.removeLayer(annLayer.getIndex());
>> 	        newannLayer.setName(sLayerName);
>>   
>>     
>
>
>
> Email has been scanned for viruses and spam by Altman Technologies'
> email management service - www.altman.co.uk/emailsystems
>
> Email has been scanned for viruses and spam by Altman Technologies' email management service - www.altman.co.uk/emailsystems
>
>
>   



More information about the MapServer-users mailing list