Solved

VB6 ImageList control prevent Terminate Event

Posted on 2016-08-11
11
56 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 48

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

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
 
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 48

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 48

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

615 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