fix some memleak

This commit is contained in:
侯歌 2024-04-13 17:16:20 +08:00
parent 937d82c781
commit 30298fbc57
5 changed files with 14 additions and 7 deletions

View File

@ -19,13 +19,17 @@ public:
template<typename T>
class SimplePool:public Pool<T>{
private:
int maxPoolSize;
std::vector<T*> mPool;
int maxPoolSize;
std::vector<T*> mPool;
public:
SimplePool(int maxPoolSize) {
SimplePool(int maxPoolSize) {
LOGE_IF(maxPoolSize <= 0,"The max pool size must be > 0");
this->maxPoolSize = maxPoolSize;
for(int i=0;i<maxPoolSize;i++)mPool.push_back(new T());
this->maxPoolSize = maxPoolSize;
for(int i=0;i<maxPoolSize;i++)mPool.push_back(new T());
}
~SimplePool(){
for(int i=0;i<maxPoolSize;i++)delete mPool.at(i);
mPool.clear();
}
T* acquire() {
if (!mPool.empty()) {

View File

@ -8,7 +8,7 @@ GridLayoutManager::GridLayoutManager(Context* context,const AttributeSet& attrs)
Properties* properties = getProperties(context, attrs,0,0);// defStyleAttr, defStyleRes);
mSpanSizeLookup = new DefaultSpanSizeLookup();
setSpanCount(properties->spanCount);
delete properties;
delete properties;
}
GridLayoutManager::GridLayoutManager(Context* context, int spanCount)

View File

@ -27,6 +27,7 @@ LinearLayoutManager::LinearLayoutManager(Context* context, const AttributeSet& a
setOrientation(properties->orientation);
setReverseLayout(properties->reverseLayout);
setStackFromEnd(properties->stackFromEnd);
delete properties;
}
LinearLayoutManager::~LinearLayoutManager(){

View File

@ -67,11 +67,11 @@ RecyclerView::RecyclerView(int w,int h):ViewGroup(w,h){
RecyclerView::RecyclerView(Context* context,const AttributeSet& attrs)
:ViewGroup(context, attrs){
mClipToPadding = attrs.getBoolean("clipToPadding", true);
initRecyclerView();
initAdapterManager();
initChildrenHelper();
initAutofill();
mClipToPadding = attrs.getBoolean("clipToPadding", true);
// If not explicitly specified this view is important for accessibility.
if (getImportantForAccessibility()
== View::IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
@ -128,6 +128,7 @@ void RecyclerView::initRecyclerView(){
mIsAttached = false;
mHasFixedSize = true;
mEnableFastScroller = false;
mClipToPadding = true;
mIgnoreMotionEventTillDown = false;
mPostedAnimatorRunner = false;
mDataSetHasChangedAfterLayout = false;

View File

@ -17,6 +17,7 @@ StaggeredGridLayoutManager::StaggeredGridLayoutManager(Context* context,const At
setSpanCount(properties->spanCount);
setReverseLayout(properties->reverseLayout);
createOrientationHelpers();
delete properties;
}
StaggeredGridLayoutManager::StaggeredGridLayoutManager(int spanCount, int orientation) {