Allen
Allen

Reputation: 13

vb6 create an object twice, will cause memory leakage or not?

I just want to check if I write following codes in vb6:

dim a as new b
dim a as new b

will it cause the memory leak or not?

Upvotes: 1

Views: 115

Answers (2)

Mike Weir
Mike Weir

Reputation: 3189

That code won't even compile because you are defining A twice.

However, in this example:

Dim A As B
Set A = New B
Set A = New B

After the third line, the first instance of B stored in A on the second line will be destroyed.

Upvotes: 3

Derek Tomes
Derek Tomes

Reputation: 4007

No, this will not cause a memory leak.

You can also put this code in a loop of 10000 iterations and look at your memory in Task Manager.

Upvotes: 2

Related Questions