Merge "Fix a large native memory leak."

This commit is contained in:
Jean Chalard 2012-04-16 01:28:40 -07:00 committed by Android (Google) Code Review
commit 69cf85d8e3

View file

@ -26,6 +26,7 @@ namespace latinime {
class WordsPriorityQueuePool { class WordsPriorityQueuePool {
public: public:
WordsPriorityQueuePool(int mainQueueMaxWords, int subQueueMaxWords, int maxWordLength) { WordsPriorityQueuePool(int mainQueueMaxWords, int subQueueMaxWords, int maxWordLength) {
// Note: using placement new() requires the caller to call the destructor explicitly.
mMasterQueue = new(mMasterQueueBuf) WordsPriorityQueue(mainQueueMaxWords, maxWordLength); mMasterQueue = new(mMasterQueueBuf) WordsPriorityQueue(mainQueueMaxWords, maxWordLength);
for (int i = 0, subQueueBufOffset = 0; for (int i = 0, subQueueBufOffset = 0;
i < MULTIPLE_WORDS_SUGGESTION_MAX_WORDS * SUB_QUEUE_MAX_COUNT; i < MULTIPLE_WORDS_SUGGESTION_MAX_WORDS * SUB_QUEUE_MAX_COUNT;
@ -36,6 +37,11 @@ class WordsPriorityQueuePool {
} }
virtual ~WordsPriorityQueuePool() { virtual ~WordsPriorityQueuePool() {
// Note: these explicit calls to the destructor match the calls to placement new() above.
if (mMasterQueue) mMasterQueue->~WordsPriorityQueue();
for (int i = 0; i < MULTIPLE_WORDS_SUGGESTION_MAX_WORDS * SUB_QUEUE_MAX_COUNT; ++i) {
if (mSubQueues[i]) mSubQueues[i]->~WordsPriorityQueue();
}
} }
WordsPriorityQueue* getMasterQueue() { WordsPriorityQueue* getMasterQueue() {