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

@ -18,9 +18,9 @@ bool ItemTouchHelper::onInterceptTouchEvent(RecyclerView& recyclerView,MotionEve
mInitialTouchX -= animation->mX;
mInitialTouchY -= animation->mY;
endRecoverAnimation(*animation->mViewHolder, true);
auto it=std::find(mPendingCleanup.begin(),mPendingCleanup.end(),animation->mViewHolder->itemView);
auto it=std::find(mPendingCleanup.begin(),mPendingCleanup.end(),animation->mViewHolder->itemView);
if (it!=mPendingCleanup.end()){//remove(animation->mViewHolder->itemView)) {
mPendingCleanup.erase(it);
mPendingCleanup.erase(it);
mCallback->clearView(*mRecyclerView, *animation->mViewHolder);
}
select(animation->mViewHolder, animation->mActionState);
@ -165,6 +165,7 @@ void ItemTouchHelper::destroyCallbacks() {
for (int i = recoverAnimSize - 1; i >= 0; i--) {
RecoverAnimation* recoverAnimation = mRecoverAnimations.at(0);
mCallback->clearView(*mRecyclerView, *recoverAnimation->mViewHolder);
delete recoverAnimation;
}
mRecoverAnimations.clear();
mOverdrawChild = nullptr;
@ -250,7 +251,7 @@ void ItemTouchHelper::select(RecyclerView::ViewHolder* selected, int actionState
bool preventLayout = false;
if (mSelected != nullptr) {
RecyclerView::ViewHolder* prevSelected = mSelected;
RecyclerView::ViewHolder* prevSelected = mSelected;
if (prevSelected->itemView->getParent()) {
const int swipeDir = prevActionState == ACTION_STATE_DRAG ? 0
: swipeIfNecessary(*prevSelected);
@ -557,6 +558,7 @@ void ItemTouchHelper::endRecoverAnimation(RecyclerView::ViewHolder& viewHolder,
anim->cancel();
}
mRecoverAnimations.erase(mRecoverAnimations.begin()+i);//remove(i);
delete anim;
return;
}
}

View File

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

View File

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