Track memory on heap (Garbage Collection)

how to trace memory leak in c++? Suggest some method to individually trace memory taken by objects in heap?
Is this for study, or do you have an actual problem?
I an trying to design a garbage collector.

So i want to find out ways to track memory usage of APIs/Functions in C++.

Example GetData(structObj, *classObj);

If GetData() is leaking memory, it can leak only via structObj and *classObj as they are the only memory we have provided to it.
I need to track what is happening to the memory of structObj and *classObj inside GetData();

I an trying to design a garbage collector.
did you review the existing ones, like whatever Boehm's is these days - looks like it's now https://github.com/ivmai/bdwgc

I need to track what is happening to the memory of structObj and *classObj inside GetData();
statically or dynamically? Again, start by reviewing state-of-the-art leak checkers like MSVC's (static) and valgrind (dynamic).
Also, leak tracing is a very different job from garbage collection.
Last edited on
Overloading new and delete might be what you are looking for.
https://www.modernescpp.com/index.php/overloading-operator-new-and-delete
I personally think implementing garbage collection in C++ in counter productive, I don't want to distract you from you from plans of doing it, but from my humble experience I've seen it done mostly by people inclined to managed languages, usually in bigger projects (ex. unreal engine)

Garbage collection IMHO only adds unnecessary bloat to code negating language benefits, as if smart pointers are not good enough to achieve the goal, and reduce the possibility of leaks.

Thomas1965, gave you good suggestion how to start it, overloading new/delete to track memory allocations.

Anyway I've never done it myself so I my be wrong on this, but would really like someone to tell me what are the benefits and some good reasons and why it should be done compared to normal means of managing memory?
Topic archived. No new replies allowed.