am 80470cdf
: Merge "Solve three memory leaks related to PatchCache"
* commit '80470cdf6c6995f4afe8d5e2c4b6e898625173fb': Solve three memory leaks related to PatchCache
This commit is contained in:
@ -36,6 +36,7 @@ Patch::Patch(): vertices(NULL), verticesCount(0), indexCount(0), hasEmptyQuads(f
|
|||||||
}
|
}
|
||||||
|
|
||||||
Patch::~Patch() {
|
Patch::~Patch() {
|
||||||
|
delete[] vertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -119,6 +119,17 @@ void PatchCache::remove(Vector<patch_pair_t>& patchesToRemove, Res_png_9patch* p
|
|||||||
|
|
||||||
void PatchCache::removeDeferred(Res_png_9patch* patch) {
|
void PatchCache::removeDeferred(Res_png_9patch* patch) {
|
||||||
Mutex::Autolock _l(mLock);
|
Mutex::Autolock _l(mLock);
|
||||||
|
|
||||||
|
// Assert that patch is not already garbage
|
||||||
|
size_t count = mGarbage.size();
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
if (patch == mGarbage[i]) {
|
||||||
|
patch = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG_ALWAYS_FATAL_IF(patch == NULL);
|
||||||
|
|
||||||
mGarbage.push(patch);
|
mGarbage.push(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,8 +154,8 @@ void PatchCache::clearGarbage() {
|
|||||||
for (size_t i = 0; i < patchesToRemove.size(); i++) {
|
for (size_t i = 0; i < patchesToRemove.size(); i++) {
|
||||||
const patch_pair_t& pair = patchesToRemove[i];
|
const patch_pair_t& pair = patchesToRemove[i];
|
||||||
|
|
||||||
// Add a new free block to the list
|
// Release the patch and mark the space in the free list
|
||||||
const Patch* patch = pair.getSecond();
|
Patch* patch = pair.getSecond();
|
||||||
BufferBlock* block = new BufferBlock(patch->offset, patch->getSize());
|
BufferBlock* block = new BufferBlock(patch->offset, patch->getSize());
|
||||||
block->next = mFreeBlocks;
|
block->next = mFreeBlocks;
|
||||||
mFreeBlocks = block;
|
mFreeBlocks = block;
|
||||||
@ -152,6 +163,7 @@ void PatchCache::clearGarbage() {
|
|||||||
mSize -= patch->getSize();
|
mSize -= patch->getSize();
|
||||||
|
|
||||||
mCache.remove(*pair.getFirst());
|
mCache.remove(*pair.getFirst());
|
||||||
|
delete patch;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_PATCHES
|
#if DEBUG_PATCHES
|
||||||
@ -216,6 +228,7 @@ void PatchCache::setupMesh(Patch* newMesh, TextureVertex* vertices) {
|
|||||||
} else {
|
} else {
|
||||||
mFreeBlocks = block->next;
|
mFreeBlocks = block->next;
|
||||||
}
|
}
|
||||||
|
delete block;
|
||||||
} else {
|
} else {
|
||||||
// Resize the block now that it's occupied
|
// Resize the block now that it's occupied
|
||||||
block->offset += size;
|
block->offset += size;
|
||||||
|
Reference in New Issue
Block a user