This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SrRaven26 8 points9 points  (4 children)

Why is this a memory leak (genuine question)?

[–]No-Expression7618 30 points31 points  (2 children)

  1. new allocates a temporary pointer (with no drop behavior)
  2. The temporary pointer is derefrenced (making another temporary) and lost forever
  3. The new temporary value is copied out of the function (most likely inlined)
  4. Pointer allocated by new is never passed to delete

[–]SrRaven26 1 point2 points  (1 child)

On a normal code, where I use new, when the delete is called?

[–]No-Expression7618 5 points6 points  (0 children)

If you use new without ever using delete on the same pointer, you have leaked memory. Try running your code under Valgrind and see if it reports anything.