|
-
January 10th, 2009, 11:30 AM
#16
Re: Memory Leak Questions
 Originally Posted by TheCPUWizard
that is not what this topic is about. We are talking about a student at a very early point in the learning processs...
I don't think it's fair to assume that the OP is still in the beginning stages of his education, so the topic should have little to do with that. If this is a project for an introductory course, I'm inclined to say that the professor is totally out of his mind... in an admirable way.
I agree with your concerns regarding C++ education, but I've seen the argument in a lot of threads and this thread is no better a soap-box than the last. I don't think the chairperson of any offending institution is following our conversation.
 Originally Posted by dada27
Do i need to delete all the SettingsManager::CommandParameter *Pointers that i have on the DBInterface Header, on the Destruction of the DBInterface ???
It depends. The basic principle of memory management is that if you allocate memory, you must know exactly how it gets deallocated - including the case where an exception alters your program execution. If you expect someone else to delete it (a very bad design in most cases), you must clearly say so in the documentation. Conversely, if you are handed a piece of memory by third party code (in which case you are a victim of bad design), you should always consult their documentation.
So, the question I have to ask before I can reasonably give an answer is what allocates the memory in question and what is the expectation at that point as to how it gets deallocated?
There's a postscript to all of this, which is basically what most of the discussion in this thread has been about: You should know how to manage memory, but in practice manual memory management should be avoided at all costs in code that is not specifically designed for the purpose of memory management. A database interface is not a memory management scheme, so do not make it so. Use STL containers and smart pointers for that purpose if at all possible (but as exterminator pointed out, this is not always an option).
As a final note, unless you switch from raw pointers to containers and smart pointers (which you should), you must either implement a public/protected copy constructor and assignment operator, or declare them private and leave them unimplemented.
Last edited by Hermit; January 10th, 2009 at 11:37 AM.
- Alon
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|