-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Update Marker Icon doesn't result in AnnotationManager::removeAnnotationIcon #7343
Comments
@AlexeyIke Looking at the code you posted I'm seeing that you are constantly creating new bitmaps/icons. These are memory intensive tasks and you should optimise your code to avoid creating new objects if not needed. Could you provide us so more information on this by profiling the code an seeing where the large amounts of memory allocations are occurring? |
Hello, I mean memory leak beacause if i change icon for marker previous icon should be delete by GC, but no mem free happen for markers - used memory grows up and even when i init GC from AndroidStudio not free memory. Screenshot - https://drive.google.com/open?id=0B3U64R1No4k8NmdIcjNpcUNfT2c Another way for my project - instead if changind icon just delete and add markers. So, i need to know keeping changed markers icons in memory normal or bug? |
Thank you for clarifying those statements, very helpful! The reason why you don't see memory being freed with invoking a java gc is that the Bitmap is passed through jni as a bytebuffer and is than is placed in a SpriteAtlas with Re. your use-case, I would highly advice you to look at runtime styling API instead of using the marker API. This API is much more flexible and you should be able to handle your use-case without creating any bitmaps at all. I think this cluster example should help you get started. Thanks again for taking the time to write this up and making our SDK better. |
Hello, thanks for cluster example! Works well.
Can i reach additional functionality?
- define custom icon for cluster/icon (i saw define iconImage"marker-15"
but how define own image),
- change cluster icon programatically (for example i want to hightligh
"touched" cluster)
- animate re-clustering
May be some examples exists?
2016-12-09 17:16 GMT+10:00 Tobrun <notifications@github.com>:
… Thank you for clarifying those statements, very helpful! The reason why
you don't see memory being freed with invoking a java gc is that the Bitmap
is passed through jni as a bytebuffer and is than is placed in a
SpriteAtlas with AnnotationManager::addIcon. I will not be possible to
let the java gc clean that up. The only way would be to explicitly call
AnnotationManager::removeIcon, while this is supported in the C++ we
still need to expose the proper binding for it. We also need to check if we
can automatically hook this up when you are replacing an icon.
Re. your use-case, I would highly advice you to look at runtime styling
API instead of using the marker API. This API is much more flexible and you
should be able to handle your use-case without creating any bitmaps at all.
I think this
<https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GeoJsonClusteringActivity.java#L121>
cluster example should help you get started.
Thanks again for taking the time to write this up and making our SDK
better.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#7343 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ARNVET2nF0LC9RgLkgU9YwrkhS_XP4PPks5rGQAygaJpZM4LHlEx>
.
|
Platform:Android
Mapbox SDK version:android-v4.2.0-beta.4
Steps to trigger behavior
Expected behavior
Markers change icon and position
Actual behavior
Memory leak - used memory grows on every icon change.
When i use mapboxMap.addMarker(new MarkerViewOptions().position(position)) for each marker add - everything works well.
For my project i need to draw many markers (about 200 - 300) and periodicaly change its position and icon.
With mapboxMap.addMarker(new MarkerViewOptions().position(position)) func adding i has memory leak. May be not using addMarkers method?
Example with memory leak i've make base on mapbox demo // AnimatedIconActivity:
package com.mapbox.mapboxandroiddemo.examples.annotations;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import com.mapbox.mapboxandroiddemo.R;
import com.mapbox.mapboxsdk.MapboxAccountManager;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import java.util.ArrayList;
import java.util.List;
public class AnimatedMarkerActivity extends AppCompatActivity {
private MapView mapView;
Handler handler = new Handler();
List mlist = new ArrayList<>();
Paint paint;
static int i=0;
Runnable runnable;
MapboxMap mmapboxMap;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@OverRide
public void onResume() {
super.onResume();
mapView.onResume();
}
@OverRide
public void onPause() {
super.onPause();
mapView.onPause();
}
@OverRide
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@OverRide
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@OverRide
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
private static class LatLngEvaluator implements TypeEvaluator {
// Method is used to interpolate the marker animation.
}
private Icon getIcon(int i, Paint paint){
Bitmap bitmap;
}
public static Bitmap drawTextOnBitmap(String text, Paint paint, Bitmap source) {
Bitmap mutableBitmap = source.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);
}
}
The text was updated successfully, but these errors were encountered: