HandOfCode
HandOfCode

Reputation: 29

VB6 memory leak from CreateObject

I'm using an eternal library (DLL) to load in a certain file format and have found out that the load function doesn't actually load. It will load the first time it's called for the same object but if I call it again to open a new file it doesn't always load. This has forced me to call CreateObject each time I want to load a new file. The problem with this is VB6 doesn't seem to free up the old object at all and the RAM and VM usage quickly bloats to the GBs.

Is there a way to force this to free up? setting the variable to "Nothing" or "Null" doesn't do anything and the app will bloat so much it will actually run out of memory and crash. (I have to run it inside a VM since the IDE is so old it doesn't work on Win7, well I couldn't get it to work)

I've looked for circular references but there aren't any, the file is loaded using that object, the properties of the file are read into an ADO object, and the actual file itself is never referenced into the ADO object, just various fields from it.

Upvotes: 0

Views: 2031

Answers (1)

Warren Rox
Warren Rox

Reputation: 645

Whether you have a direct reference in your VB6 project or use "CreateObject" to instantiate your object reference will not matter. If the third party component has a memory leak you'll experience the same behaviour either way.

If you are instantiating an unmanaged resource you will need to call "Dispose". Other than that, the object instance will fall "out of scope" when the method call has completed and the Visual Basic Runtime shall clean up the reference (using reference counting). If the third party component does indeed have a memory leak you'll need to have them patch the DLL as there will be nothing you can do to prevent it.

Upvotes: 1

Related Questions