[英]Android Wear 2.0 Memory Leak
I created a blank Android Wear 2.0 stand-alone app project in Android Studio. 我在Android Studio中创建了一个空白的Android Wear 2.0独立应用程序项目 。 I noticed that when I run the blank app on my watch there seems to be a memory leak (shown below).
我注意到,当我在手表上运行空白应用程序时,似乎存在内存泄漏(如下所示)。 Is anyone else experiencing this issue?
还有其他人遇到这个问题吗?
The device I'm testing it on is an LG Watch Style, running Android Wear 2.0 我正在测试的设备是运行Android Wear 2.0的LG Watch Style
This is a blank project, here is the code: 这是一个空白项目,代码如下:
MainActivity.java MainActivity.java
import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;
public class MainActivity extends WearableActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
AndroidManifest.xml AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mc.memorytester">
<uses-feature android:name="android.hardware.type.watch"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault">
<uses-library
android:name="com.google.android.wearable"
android:required="false"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault.Light">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
build.gradle 的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.mc.memorytester"
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:2.0.3'
compile 'com.google.android.gms:play-services-wearable:11.0.4'
provided 'com.google.android.wearable:wearable:2.0.3'
}
This doesn't look like a memory leak. 这看起来不像是内存泄漏。 If you were in fact leaking, the total amount of used memory would keep increasing over time, and eventually cause a very sluggish experience and/or an
OutOfMemoryException
. 如果实际上是在泄漏,则使用的内存总量将随着时间的推移而不断增加,并最终导致非常缓慢的体验和/或
OutOfMemoryException
。 What you see here are cycles of objects being created, and then garbage collected. 您在此处看到的是创建对象的周期,然后是垃圾回收。
There are still things you can do to improve this, since frequent garbage collection might result in hiccups/lag. 您仍然可以采取一些措施来改善此问题,因为频繁的垃圾收集可能会导致打ic /滞后。
My suggestion is to take a look at methods that are executed often ( onDraw()
and similar things) and make sure that you're not creating objects inside of them. 我的建议是看一下经常执行的方法(
onDraw()
和类似的东西),并确保您未在其中创建对象。 If that doesn't help you can use the Android Profiler to dig deeper and find out what's being created (details about how you do that can be found eg here ) 如果这样做没有帮助,您可以使用Android Profiler进行更深入的了解,找出正在创建的内容(有关操作方法的详细信息,例如,可以在此处 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.