[OpenLayers-Users] removeFeatures vs. destroyFeatures behavior

Eric Lemoine eric.c2c at gmail.com
Wed Jul 23 00:26:18 EDT 2008


Hi Ian. removeFeatures removes the feature from the layer (and from
the feature array) but the features aren't destroyed, for example they
can later be added back to the layer. After removeFeatures the layer
has no references on the layers, user code is therefore responsible
for destroying the features and releasing references so that the
features are garbage-collected. After destroyFeatures the features are
removed from the layer and destroyed. Like after removeFeatures they
shouldn't reappear on the layer after redraw, if you observe otherwise
it's certainly a bug that we need to track down. Cheers. Eric

2008/7/22, Ian <iansgis at gmail.com>:
> Hello,
>
> I am drawing "highlight" circles in a vector layer as users select/deselect
> features from another layer. After reading the docs and list I got the
> impression that removeFeatures would remove a feature from the map but that
> it would continue to exist in the features array and could lead to memory
> leaks if overused. destroyFeatures on the other hand sounded like it would
> permanently remove the feature from the map and array.
>
> However I'm getting the opposite behavior. removeFeatures deletes the
> feature and it is gone from the features array (redrawing the layer also
> confirms this). destroyFeatures removes the feature from the map, but the
> feature remains in the features array and redrawing the layer redraws the
> deleted feature as well. Am I missing something?
>
> Code snippets:
>
> selFeatures = new OpenLayers.Layer.Vector("Selected Features", {style:""});
>
> function updateSavedFeatures (name) {
>   ...
>   // Add highlight
>   highlight = new OpenLayers.Feature.Vector(new
> OpenLayers.Geometry.Point(saved[name].lon, saved[name].lat));
>   highlight.fid = name;
>   selFeatures.addFeatures(highlight);
>   ...
>   // Remove highlight
>   for (var key in selFeatures.features) {
>     if (selFeatures.features[key].fid == name) {
>       selFeatures.removeFeatures(selFeatures.features[key]);
>       //selFeatures.destroyFeatures(selFeatures.features[key]);
>     }
>   }
> }
>



More information about the Users mailing list