Multi-thread causes memory leak


#1

my main class has a hashmap member, and the class creates a thread to do the data checking, in the thread proc it will use the hashmap member.

when the user terminates the app, the created thread still uses the hashmap member which is already freed by the main class.

so the IDE reports errors:

HEAP: Free Heap block 55fb10 modified at 55fb58 after it was freed

*** Leaked objects detected: 1 instance(s) of class HashMap
JUCE Assertion failure in juce_leakedobjectdetector.h:95

 

i know the reason but i can't find a good way to resolve this.

so any suggestions? thank you.
 


#2

ReferenceCountedObjectPtr might be what you need..