Discussion Thread
UniToolbox
Message Thread
The leading control suite for Unicode development in Visual Basic.
Posted in the UniToolbox Forum.
Memory leak?
Hi.
I'm currently evaluating the UniToolbox 2, and I think there is a memory leak.
1. Load Form2 by using another (Form1).
2. In the load-event of Form2 load 200 UniTextBoxes.
3. Then unload Form2 and therefore the 200 UniTextboxes.
4. After about 5 Minutes periodical load and unload (using a Timer in Form1) memory durable increases.
Equal if you separately unload the UniTextboxes in the unload-event or queryunload-event.
Mike
Memory leak?
Sorry for the delay in replying Mike, we're looking into the issue. Can I ask how much memory you see leaking?
Memory leak?
Hi Nico,
i've tested it for 12 passes. Here the list of the memory allocation:
7512; 7544; 7656; 7636; 7668; 7656; 7700; 7716; 7764; 7756; 7764; 7776 (KB)
GDI objects seems ok.
Mike
Enclosed then code, its not very tricky ;-)
Form1 -----------------------------
Option Explicit
Dim blnStop As Boolean
Private Sub Command1_Click()
'Timer1.Interval = 200
'Timer1.Enabled = True
Form2.Show
End Sub
Private Sub Command2_Click()
blnStop = True
End Sub
Private Sub Timer1_Timer()
Static lngLoop As Long
If Not CBool(lngLoop Mod 5) Then
Form2.Show
End If
End Sub
Form2 ----------------------------------------
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim lngi As Long
For lngi = 201 To 2 Step -1
Unload UniText2(lngi - 1)
Next lngi
DoEvents
End Sub
Private Sub Timer1_Timer()
Dim lngi As Long
Dim lngK As Long
For lngi = 1 To 200
Load UniText2(lngi)
UniText2(UniText2.Count - 1).Visible = True
UniText2(UniText2.Count - 1).Top = UniText2(UniText2.Count - 1).Top + (lngK)
UniText2(UniText2.Count - 1).BackColor = RGB(Rnd(1) * 255, Rnd(1) * 255, Rnd(1) * 255)
DoEvents
lngK = lngK + 50
Next lngi
Unload Me
End Sub
Memory leak?
Hi Nico,
is there a solution for my problem?
Mike
Memory leak?
Mike,
We've been looking at the issue and it does appear that there are some memory issues with a large number of controls created in this way. Unfortunately we don't have a simple solution for you at this time other than to just grin and bear it, or to create the controls using the standard method.
Memory leak?
Hi Nico,
thanks or reply.
Ouh, you think this is a large number of controls, there are only 200 controls.
We are working on a 24/7 application. Ok, the application is ready for a long time but now we have to translate it in russian.
So, in a industrially used 24/7 application grin and bear is not the right attitude.
What is the standard method to create controls when do not know the number?
Mike
Memory leak?
Please see James's response below, he has a better handle on the situation.
Memory leak?
I do not believe that the data you have collected implies a memory leak. If fact, because at times the memory usage actually decreases I would be confident in saying there is not a memory leak. Memory either leaks or it does not - it does not happen only sometimes when repeatedly performing the same set of actions.
It is far more that the fluctuations in memory allocation you are seeing are simply caused by the VB Runtime's memory management and garbage collection system as it modifies the memory required by the program.
I have run you code for a short while and concluded that the memory usage stabilises quite quickly before continuing to fluctuate within a small range.
By the way, although you think the Form2 is actually being unloaded, it is not being destroyed until the program has terminated (Try 'MsgBox "Form2_Form_Terminate()"' in the Form_Terminate() event). This is because you are using the Form2 without defining a specific instance variable. VB will create its own variable and manage its lifetime according to its own rules.
You also don't really need to unload the control array explicitly; when the form is unloaded, any controls it contains will also be unloaded.
I hope this helps.
Memory leak?
Hi,
we practice this for many years.
If we use the standard VB.Textbox it works fine.
if you create a usercontrol, we have already made this too, you have take care of this:
M$: Q190511
Mike