blengerich / GenAMap

Visual Machine Learning of Genome-Phenome Associations
http://genamap.org
MIT License
22 stars 7 forks source link

change current Singleton to Meyers Singleton to avoid memory leak #184

Closed weifang1 closed 7 years ago

weifang1 commented 7 years ago

The current implementation of Singleton requires users to manually delete the instance and there is no such code to do that so there would be memory leaks. Actually, in C++11, Meyers Singleton is a simpler and more powerful way to do that: https://github.com/blengerich/GenAMap/blob/valgrind_check/src/Scheduler/Scheduler.cpp#L94

Some explanations about Meyers Singleton: http://stackoverflow.com/a/17713799

This modification can eliminate most memory leaks in the scheduler. There are still some other leaks (128 bytes) but it seems that they come from uv_queue_work().