Skip to content

fix: onRemove does not clear internal state #73

@wazolab

Description

@wazolab

Severity

P2 — Memory leak / stale state

Description

In `src/teritorio-cluster.ts:123-133`, `onRemove` removes markers and event listeners but does not reset internal state:

  • `this.markersOnScreen` — still populated after removal
  • `this.clusterLeaves` — retains stale cluster data
  • `this.featuresMap` — retains stale feature data
  • `this.selectedFeatureId` — still references a feature
  • `this.map` — still references the map instance
  • `this.source` — still references the source

If the instance is held by consumer code after layer removal, these references prevent garbage collection of the map, source, and all DOM elements referenced by features.

Suggested Fix

Add state cleanup at the end of `onRemove`:
```ts
this.markersOnScreen.clear()
this.clusterLeaves.clear()
this.featuresMap.clear()
this.selectedFeatureId = null
this.map = null
this.source = null
```

Files

  • `src/teritorio-cluster.ts:123-133`

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions