It really is up to you.
A good object-oriented approach is for the class itself to manage memory. Most of the benefits of OOP are that it encapsulates functionality as best as possible. That way, you can create it in such a way that the code calls your class methods without worrying about how memory is allocated or freed, because it is controlled by the class.
However, there are times when this approach does not work, because there is no good way to find out the class when memory is no longer required. In these cases, you can either simply allocate memory to the caller (and then free it), or simply indicate that the caller must free the memory that was allocated and returned from the class.
This is done in both directions. There are no real hard rules.
source share