xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/loading_bg"
android:orientation="vertical"> <FrameLayout
android:id="@+id/lLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/loading_bg"
android:orientation="vertical"> <com.xxx.xxx.app.web.MySurfaceView
android:id="@+id/sv"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</com.xxx.xxx.app.web.MySurfaceView >
......
java 代码:
..... mSurfaceView = (MySurfaceView) mMainView.findViewById(R.id.sv);
SurfaceHolder sh = mSurfaceView.getHolder();
sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
sh.addCallback(this);
.....
MySurfaceViewpublic class MySurfaceView extends SurfaceView {
private static final String TAG ="BesTVSurfaceView";
public MySurfaceView (Context context) {
super(context);
} public MySurfaceView (Context context, AttributeSet attrs) {
super(context, attrs);
}
public MySurfaceView (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
private void initView() {
Log.d(TAG,"initView");
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
initView();
}
}
LeakCanary 内存泄漏分析工具
结果日志:
* com.xxx.xxx.app.MainActivity has leaked:
* GC ROOT static android.view.SurfaceView.mSurfaceContext
* leaks com.xxx.xxx.app.MainActivity instance[/code]
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/loading_bg"
android:orientation="vertical"> <FrameLayout
android:id="@+id/lLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/loading_bg"
android:orientation="vertical"> <com.xxx.xxx.app.web.MySurfaceView
android:id="@+id/sv"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</com.xxx.xxx.app.web.MySurfaceView >
......
java 代码:
..... mSurfaceView = (MySurfaceView) mMainView.findViewById(R.id.sv);
SurfaceHolder sh = mSurfaceView.getHolder();
sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
sh.addCallback(this);
.....
MySurfaceViewpublic class MySurfaceView extends SurfaceView {
private static final String TAG ="BesTVSurfaceView";
public MySurfaceView (Context context) {
super(context);
} public MySurfaceView (Context context, AttributeSet attrs) {
super(context, attrs);
}
public MySurfaceView (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
private void initView() {
Log.d(TAG,"initView");
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
initView();
}
}
LeakCanary 内存泄漏分析工具
结果日志:
* com.xxx.xxx.app.MainActivity has leaked:
* GC ROOT static android.view.SurfaceView.mSurfaceContext
* leaks com.xxx.xxx.app.MainActivity instance[/code]
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货