Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

#Actualrnlf

Posted 12 July 2012 - 02:50 AM

I'm sorry, but this is wrong. What happens if an exception is thrown between your new and the matching delete? Or you refactor your code months later and you insert a return statement somewhere in the middle. Your pointer will go out of scope, the delete will never be executed. Result: Memory leak. If you use new without a smart pointer, you most like do not know, what you are doing, thus must not use it. There may be a few exceptions to this, but you will have to think really hard before doing it.

Yes, you can just allocate it on the stack which is a much better idea, if it fits the rest of your program (like you can't return the memory from a function then).

#3rnlf

Posted 12 July 2012 - 02:49 AM

I'm sorry, but this is wrong. What happens if an exception is thrown between your new and the matching delete? Your pointer will go out of scope, the delete will never be executed. Result: Memory leak. If you use new without a smart pointer, you most like do not know, what you are doing, thus must not use it. There may be a few exceptions to this, but you will have to think really hard before doing it.

Yes, you can just allocate it on the stack which is a much better idea, if it fits the rest of your program (like you can't return the memory from a function then).

#2rnlf

Posted 12 July 2012 - 02:48 AM

I'm sorry, but this is wrong. What happens if an exception is thrown between your new and the matching delete? Your pointer will go out of scope, the delete will never be executed. Result: Memory leak. If you use new without a smart pointer, you most like do not know, what you are doing, thus must not use it.

Yes, you can just allocate it on the stack which is a much better idea, if it fits the rest of your program (like you can't return the memory from a function then).

#1rnlf

Posted 12 July 2012 - 02:47 AM

I'm sorry, but this is wrong. What happens if an exception is thrown between your new and the matching delete? Your pointer will go out of scope, the delete will never be executed. Result: Memory leak.

Yes, you can just allocate it on the stack which is a much better idea, if it fits the rest of your program (like you can't return the memory from a function then).

PARTNERS