Do I have to, and how can I, free memory from a class created in a Windows Runtime Component that has been returned to a managed C# project?
This question concerns Classes instead of structs like How to free memory of c++ WinRT value structs
The following scenario occurs
I want to be sure the following classes wont create memory leaks: https://github.com/cmusphinx/pocketsphinx-wp-demo/blob/master/PocketSphinxRntComp/SpeechRecognizer.h#L32
I'm (still) new with freeing memory and haven't got a clue how and when to free this. Anyone?
All ref
classes are reference-counted and will automatically be freed when there are no more live references. Because .NET uses a garbage collector, the memory might not be freed right away.
If you have circular references in your app or library then the reference count of the objects will never hit zero and the memory will not be reclaimed (.NET can deal with circular references if all the objects are managed, but not if they come from outside the managed world, like your C++ classes).
Whether or not your C++ code has internal memory leaks is another question.