|
|
On Thu, 20 Mar 2008 00:52:55 +0100, stbenge <stb### [at] hotmailcom> wrote:
> Say I wrote
>
> int** foo = NULL;
> int nx = 22, ny = 17;
>
> void matrixfunc(){
> foo = new int*[nx];
>
> for (int x = 0; x < nx; x++)
> foo[x] = new int[ny];
> }
Much better to use std::vector instead. Avoid raw pointers like the
plague; it will save you many headaches.
> and called matrixfunc();, but before I could delete it
>
> for (int x = 0; x < nx; x++)
> delete[] foo[x];
>
> delete[] foo;
> foo = NULL;
>
> the code crashed. Do I have a memory leak?
If by "crash" you mean unexpected program termination, then not really
(not because of the crash anyway). Any modern desktop OS will reclaim th
e
resources held by a program when said program terminates.
--
FE
Post a reply to this message
|
|