Matthew
Matthew

Reputation: 13987

Does dynamic array constructor call delete?

If I do this:

int da [];
...
da = new[2];
...
da = new[1];

Have I got a memory leak? Should I have done this:

da.delete;
da = new[1];

instead?

Upvotes: 2

Views: 334

Answers (1)

dave_59
dave_59

Reputation: 42698

No need to call delete unless you have a tool issue. Any time you make an assignment to an array as a whole, the previous array gets deleted.

However, since SystemVerilog has automatic memory management, there is no requirement when that memory gets released back to the OS.

Upvotes: 5

Related Questions