1. 独立app内存泄漏优化

This commit is contained in:
wangcongtao
2020-09-27 19:16:54 +08:00
parent 29be9de7db
commit 53d1ac0b3f
13 changed files with 62 additions and 17 deletions

View File

@@ -101,7 +101,7 @@ CRASHREPORT_NOOP_VERSION=2.0.0
######## 外部依赖引用
# 车聊聊
CARCHATTING_VERSION=1.8.6
CARCHATTING_VERSION=1.8.7
# 车聊聊接口
CARCHATTINGPROVIDER_VERSION=1.4.1
# loglib

View File

@@ -86,6 +86,7 @@ public abstract class MogoBaseMapView extends FrameLayout implements ILifeCycle
if ( mMapView != null ) {
mMapView.onDestroy();
}
MogoMap.getInstance().clear();
}
@Override

View File

@@ -46,4 +46,9 @@ public class MogoMap {
public IMogoMap getMogoMap() {
return mMap;
}
public void clear(){
mContext = null;
mMap = null;
}
}

View File

@@ -604,6 +604,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
super.onDestroyView();
isClickShare = false;
TopViewAnimHelper.getInstance().removeAllView();
TopViewAnimHelper.getInstance().clear();
}
@Override

View File

@@ -680,4 +680,20 @@ public class TopViewAnimHelper {
hideNaviView();
MapCenterPointStrategy.setMapCenterPointByScene(mogoMapUIController, Scene.AIMLESS);
}
public void clear(){
topMotionLayout = null;
remainTimeGroup = null;
remainDistanceGroup = null;
arriveTimeGroup = null;
naviBg = null;
ivTurnIcon = null;
tvNextDistance = null;
tvNextRoad = null;
tvNextDistanceUnit = null;
tvTurnInfo = null;
topContainer = null;
cameraMode = null;
transition = null;
}
}

View File

@@ -346,6 +346,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
@Override
protected void onDestroy() {
super.onDestroy();
mMogoMapService.getHostListenerRegister().unregisterMarkerClickListener();
mMogoStatusManager.setMainPageLaunchedStatus( TAG, false );
mMogoMapService = null;
mMogoMapUIController = null;
@@ -359,5 +360,8 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
mServiceApis.getOnlineCarPanelApi().clear();
ContextHolderUtil.releaseContext();
MogoModulesManager.getInstance().onDestroy();
SchemeIntent.getInstance().clear();
FloatingViewHandler.clear();
mServiceApis.getShareManager().releaseContext();
}
}

View File

@@ -55,16 +55,23 @@ public class SchemeIntent implements IMogoStatusChangedListener {
}
}
private SchemeIntent() {
// private constructor
private static volatile SchemeIntent sInstance;
private SchemeIntent(){}
public static SchemeIntent getInstance(){
if( sInstance == null ){
synchronized( SchemeIntent.class ) {
if( sInstance == null ){
sInstance = new SchemeIntent();
}
}
}
return sInstance;
}
private static final class InstanceHolder {
private static final SchemeIntent INSTANCE = new SchemeIntent();
}
public static SchemeIntent getInstance() {
return InstanceHolder.INSTANCE;
public synchronized void release(){
sInstance = null;
}
public void init( Context context, IMogoServiceApis apis ) {
@@ -73,9 +80,11 @@ public class SchemeIntent implements IMogoStatusChangedListener {
mApis.getStatusManagerApi().registerStatusChangedListener( TAG, StatusDescriptor.MAIN_PAGE_RESUME, this );
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return InstanceHolder.INSTANCE;
public void clear(){
mApis.getStatusManagerApi().unregisterStatusChangedListener( TAG, StatusDescriptor.MAIN_PAGE_RESUME, this );
mContext = null;
mApis = null;
}
public void handle( Intent intent ) {

View File

@@ -41,6 +41,10 @@ public class FloatingViewHandler {
sFloatingLayout = frameLayout;
}
public static void clear(){
sFloatingLayout = null;
}
/**
* 添加任意view到布局不考虑优先级
*

View File

@@ -67,7 +67,7 @@ class LauncherCardRefresher {
public static final long ONE_MINUTE = 60 * 1000L;
public static final long ONE_DAY = 24 * 60 * ONE_MINUTE;
private String mLaunchTTSText;
private long mDefaultTTSPlayInterval = 2 * ONE_MINUTE;
private long mDefaultTTSPlayInterval = 60 * ONE_MINUTE;
private LauncherCardAdvertisementData.LauncherCardAdvertisement mDefaultLauncherCardConfig;
private List< LauncherCardAdvertisementData.LauncherCardAdvertisement > mAdvertisements;
@@ -156,7 +156,7 @@ class LauncherCardRefresher {
private ZhidaoRefreshModel mZhidaoRefreshModel;
private LauncherCardRefreshStrategy mExplorerWayOrOnlineCarDataStrategy = new LauncherCardRefreshStrategy(
1 * ONE_MINUTE, null, MSG_EXPLORER_WAY_OR_ONLINE_CAR_DATA
40 * ONE_MINUTE, null, MSG_EXPLORER_WAY_OR_ONLINE_CAR_DATA
);
private LauncherCardRefreshStrategy mInduceStrategy = new LauncherCardRefreshStrategy(
3 * ONE_MINUTE, mExplorerWayOrOnlineCarDataStrategy, MSG_INDUCE

View File

@@ -131,6 +131,11 @@ public class ShareControl implements IMogoShareManager, IMogoIntentListener,
mContext = context;
}
@Override
public void releaseContext() {
mContext = mContext.getApplicationContext();
}
private void realShowDialog() {
if (mShareDialog == null) {
Logger.d(TAG, "realShowDialog context : " + mContext);

View File

@@ -82,7 +82,7 @@ object SeekHelpManager {
if(!isSeeking) {
isSeeking = true
if (this.context == null) {
this.context = context
this.context = context.applicationContext
}
aiAssist = AIAssist.getInstance(context)

View File

@@ -25,4 +25,6 @@ public interface IMogoShareManager extends IProvider {
* @param context 待重置的上下文
*/
void resetContext(Context context);
void releaseContext();
}

View File

@@ -30,7 +30,6 @@ public class FragmentStack {
private FragmentManager mFragmentManager;
//private FragmentTransaction mFragmentTransaction;
private int mContainerId;
private Activity mActivity;
private FragmentDescriptor mCurrentFragment;
private FragmentStackTransactionListener mFragmentStackTransactionListener;
@@ -56,7 +55,6 @@ public class FragmentStack {
}
public void init( AppCompatActivity activity, int containerId ) {
mActivity = activity;
mFragmentManager = activity.getSupportFragmentManager();
mContainerId = containerId;
}