Solved

VB6 ImageList control prevent Terminate Event

Posted on 2016-08-11
11
25 Views
Last Modified: 2016-09-23
I am helping out supporting a VB6 project that has a couple of UserControls. I have been tracking down a memory leak issue.

I've narrowed it down to one of the controls that doesn't unload properly even though it doesn't seem to be referenced elsewhere.

I've replicated the problem in a demo app, and attached it as a zip file. You'll need to rename the .txt files to .ctl before opening the project though. EE won't accept .ctl files yet.

Im summary, with the check box unchecked, the Terminate Event fires when Form2 closes (as I need it to), but when it is checked, it doesn't fire until the app closes down (form1 closes). The behavior seems to be the same both compiled and in the IDE.

I'm hoping you can help.
image-list-dispose-problem.zip
0
Comment
Question by:JedNebula
  • 5
  • 4
11 Comments
 
LVL 1

Author Comment

by:JedNebula
ID: 41752439
I have since tried changing the ImageList control for a CommandButton and the same thing happens.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 41752902
I don't know if you consider this an acceptable solution but this resolves the problem.

Private Sub Command1_Click()
Dim x As New Form2

    'x.MyProductMenu.bIgnoreSet = (chkInitImageList.Value = vbUnchecked)
    x.MyProductMenu.bIgnoreSet = True
    
    x.Show
    
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:JedNebula
ID: 41753460
Thank you Martin, but I think that just bypasses the test.

I need to pass the object reference to the child control and still have the parent control terminate event fire when it should.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 41754522
I added some Debug.Print statements to this project. I don't think I did anything else but the app shows the same results with or without the checkbox being checked.
28962832.zip
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:JedNebula
ID: 41762304
Hi Martin,

You code supresses the ImageList being passed to the button so it cannot be used.

I need the control to be passed. I just put the option not to pass it, to demonstrate that this seems to be causing the problem with the Terminate event.

I've attached the project again with example usage of the control. (the
28962832.zip
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 41762773
I've never used it but from what I've read, the Ambient.UserMode property "specifies if the environment is in design mode or end user mode". Why do you care about that and have you tested the app for memory leaks in both the IDE and as an exe?
0
 
LVL 1

Author Comment

by:JedNebula
ID: 41762824
Hi Martin,

Yes as I put in my original question, the behaviour seems the same when compiled as an exe and in the IDE.

You're right about the UserMode property's use. Tbh you could probably strip that part out of the code of you want. I just do it out of habbit because it stops the events firing when you're designing forms and only fires them when the app is running.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 41763223
In the code for MyProductMenu change

Private Sub UserControl_Terminate()

to

Public Sub UserControl_Terminate()

and in Form2 Form_Unload add

MyProductMenu.UserControl_Terminate
0
 
LVL 1

Accepted Solution

by:
JedNebula earned 0 total points (awarded by participants)
ID: 41764887
Hi Martin,

Thanks for the suggestion. I have since got round the problem my invoking a sub to clear the control reference from the child controls, then the controls seems to unload fine.

With your suggestion though, you'll notice that although the Terminate event fires, the controls are still in memory and do not unload until the app closes.

Sorry that I wasn't clear initially... I have a workaround for the issue in my actual project. I was just posting here because  I was curious as to the cause... and if anyone else had experience the same thing or could point me to a link explaining that behavior at all - so I could avoid it in the future.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now