fix some memleak of itemtouchhelper

This commit is contained in:
侯歌 2024-05-28 12:02:08 +08:00
parent c5ebaa5009
commit 1a95f27a9a
3 changed files with 10 additions and 10 deletions

View File

@ -165,6 +165,7 @@ void ItemTouchHelper::destroyCallbacks() {
for (int i = recoverAnimSize - 1; i >= 0; i--) { for (int i = recoverAnimSize - 1; i >= 0; i--) {
RecoverAnimation* recoverAnimation = mRecoverAnimations.at(0); RecoverAnimation* recoverAnimation = mRecoverAnimations.at(0);
mCallback->clearView(*mRecyclerView, *recoverAnimation->mViewHolder); mCallback->clearView(*mRecyclerView, *recoverAnimation->mViewHolder);
delete recoverAnimation;
} }
mRecoverAnimations.clear(); mRecoverAnimations.clear();
mOverdrawChild = nullptr; mOverdrawChild = nullptr;
@ -557,6 +558,7 @@ void ItemTouchHelper::endRecoverAnimation(RecyclerView::ViewHolder& viewHolder,
anim->cancel(); anim->cancel();
} }
mRecoverAnimations.erase(mRecoverAnimations.begin()+i);//remove(i); mRecoverAnimations.erase(mRecoverAnimations.begin()+i);//remove(i);
delete anim;
return; return;
} }
} }

View File

@ -174,7 +174,7 @@ public:
int viewSize, int viewSizeOutOfBounds,int totalSize, long msSinceStartScroll); int viewSize, int viewSizeOutOfBounds,int totalSize, long msSinceStartScroll);
}; };
class ItemTouchHelper::SimpleCallback:public ItemTouchHelper::Callback{// ItemTouchHelper::Callback { class ItemTouchHelper::SimpleCallback:public ItemTouchHelper::Callback{
private: private:
friend ItemTouchHelper; friend ItemTouchHelper;
int mDefaultSwipeDirs; int mDefaultSwipeDirs;
@ -232,5 +232,3 @@ public:
}; };
}/*endof namespace*/ }/*endof namespace*/
#endif/*__ITEMTOUCH_HELPER_H__*/ #endif/*__ITEMTOUCH_HELPER_H__*/

View File

@ -3,15 +3,15 @@ namespace cdroid{
LinearSmoothScroller::LinearSmoothScroller(Context* context) { LinearSmoothScroller::LinearSmoothScroller(Context* context) {
mDisplayMetrics = context->getDisplayMetrics(); mDisplayMetrics = context->getDisplayMetrics();
mLinearInterpolator = new LinearInterpolator(); mLinearInterpolator = LinearInterpolator::gLinearInterpolator.get();
mDecelerateInterpolator = new DecelerateInterpolator(); mDecelerateInterpolator = DecelerateInterpolator::gDecelerateInterpolator.get();
mTargetVectorUsable = false; mTargetVectorUsable = false;
mHasCalculatedMillisPerPixel = false; mHasCalculatedMillisPerPixel = false;
} }
LinearSmoothScroller::~LinearSmoothScroller(){ LinearSmoothScroller::~LinearSmoothScroller(){
delete mLinearInterpolator; //delete mLinearInterpolator;
delete mDecelerateInterpolator; //delete mDecelerateInterpolator;
} }
void LinearSmoothScroller::onStart() { void LinearSmoothScroller::onStart() {