VB6 Memory Leak

2019-07-27 08:53发布

Can a VB6 program that does not contain the keyword 'New' have memory leaks?

If so, please provide an example.

6条回答
Lonely孤独者°
2楼-- · 2019-07-27 09:16

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.

查看更多
狗以群分
3楼-- · 2019-07-27 09:20

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.

查看更多
看我几分像从前
4楼-- · 2019-07-27 09:21

... and don't forget memory leaks in OCXs

查看更多
姐就是有狂的资本
5楼-- · 2019-07-27 09:32

You could be calling a third party DLL that has memory leaks.

查看更多
迷人小祖宗
6楼-- · 2019-07-27 09:35

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.

查看更多
Fickle 薄情
7楼-- · 2019-07-27 09:37

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.

查看更多
登录 后发表回答