Skip to content

Commit 5fd6bcf

Browse files
kediarovgithub-actions[bot]
authored andcommitted
AnnotationManagerImpl memory leak (#10999)
https://mapbox.atlassian.net/browse/MAPSAND-2594 ## Summary - Fix native memory leak where bitmap style images added by PointAnnotation were never removed from the style when annotations were deleted via delete(), deleteAll(), or onDestroy(). - Add removeIconFromStyle / removeIconsFromStyle helpers that clean up style images with the ICON_DEFAULT_NAME_PREFIX prefix, matching the existing addIconToStyle counterpart. - The cleanup only targets auto-generated images (prefixed with icon_default_name_) so user-managed style images are unaffected. cc @mapbox/maps-android cc @mapbox/sdk-platform GitOrigin-RevId: 96531e5cdc0799404169ca092b520c759e16071a
1 parent ae3edb0 commit 5fd6bcf

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Mapbox welcomes participation and contributions from everyone.
55
> **16 KB Page Size Support:** Starting with version 11.7.0 and 10.19.0, **NDK 27 is supported** with dedicated artifacts that include [support for 16 KB page sizes](https://developer.android.com/guide/practices/page-sizes). If your app does not require 16 KB page size support, you can keep using our default artifacts without `-ndk27` suffix. For more information about our NDK support, see https://docs.mapbox.com/android/maps/guides/#ndk-support
66
77
# main
8+
## Bug fixes 🐞
9+
* Fix native memory leak in `AnnotationManager` where bitmap style images were not removed onDestroy.
810

911
# 11.20.0-rc.1 March 03, 2026
1012

plugin-annotation/src/main/java/com/mapbox/maps/plugin/annotation/AnnotationManagerImpl.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,18 @@ internal constructor(
647647
delegateProvider.mapStyleManagerDelegate.addImage(image(imageId, bitmap))
648648
}
649649

650+
private fun removeIconsFromStyle(style: MapboxStyleManager, annotations: Collection<T>) {
651+
annotations.forEach { removeIconFromStyle(style, it) }
652+
}
653+
654+
private fun removeIconFromStyle(style: MapboxStyleManager, annotation: T) {
655+
val symbol = annotation as? PointAnnotation ?: return
656+
val imageId = symbol.iconImage ?: return
657+
if (!imageId.startsWith(PointAnnotation.ICON_DEFAULT_NAME_PREFIX)) return
658+
if (!style.hasStyleImage(imageId)) return
659+
style.removeStyleImage(imageId)
660+
}
661+
650662
// Add icons to style from PointAnnotation.
651663
private fun addIconToStyle(style: MapboxStyleManager, annotations: Collection<T>) {
652664
// Add icon image bitmap from point annotation
@@ -762,6 +774,7 @@ internal constructor(
762774
style.removeStyleSource(it)
763775
}
764776
}
777+
removeIconsFromStyle(style, annotations)
765778

766779
unregisterInteractions()
767780
annotationMap.clear()

0 commit comments

Comments
 (0)