Can a VB6 program that does not contain the keyword 'New' have memory leaks?
If so, please provide an example.
Can a VB6 program that does not contain the keyword 'New' have memory leaks?
If so, please provide an example.
You could be calling a third party DLL that has memory leaks.
Yes, it could. Before I learned about a memory leak in a specific Windows API call, a VB6 program I wrote that used Transparent Blits exhibited a memory leak. So, while the leak wasn't in the program itself, it was in one of the functions that VB6 called in the Win32 API.
We had a leak using global variables in a module while running under COM+. This was a long time ago don't remember the specifics.
To summarise the answers so far: calling another component might introduce memory leaks. The component could be buggy, or you might be misusing it. The component could be an OCX or a DLL (including API calls into a Windows DLL, which is an excellent way to leak memory and windows resources not to mention lots of other thrilling problems).
And a pedantic point: you can create objects using CreateObject
, so you could leak memory through circular references without using New
. And onedaywhen has pointed out in the comments you can also create circular references with form variables without using New
. But I think the point of the question was whether VB6 memory leaks can have other causes besides circular references.
Recursive's answer does not cause a memory leak - reference counting will tidy up the memory on each execution of the loop - see my comment on the answer.
What is this obsession with New in regard to memory leaks? I don't see any relationship aside from allocating another object by touching the reference variable after setting it to Nothing.
If you do this you probably have a logic error anyway. Not using New just means you blow up instead, hardly my idea of "fixing" anything.
The worst leaks might involve API calls like those to OLE or GDI routines that require explicit cleanup/deallocation of implicitly allocated data structures.
But as I said, associating New with memory leaks sounds nuts to me.