11 Jan
2006
11 Jan
'06
4:54 p.m.
Olga Gerchikov wrote:
Is there a safe idiom to prevent memory leak? Should i use auto_ptr in C++? Or should I use the smart pointer library in boost? Which is the simplest solution?
Using a smart pointer will prevent the leak. Which smart pointer depends on your requirements. If you KNOW you only need it in the calling scope, use boost::scoped_array. Otherwise use boost::shared_array. std::auto_ptr is not applicable because it can only handle pointers allocated with new, not those allocated with new[]. Sebastian Redl