Sign in to follow this  
Followers 0
Thrain

Memory Leak

3 posts in this topic

VB.Net code

Public Class Form1

Public aTimer As System.Timers.Timer

Public Sub Main()

Dim test As Object = CreateObject("AutoItX3.Control")

End Sub

Public Sub Start()

aTimer = New System.Timers.Timer

AddHandler aTimer.Elapsed, AddressOf OnTimer

aTimer.Interval = 2500

aTimer.Enabled = True

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Start()

End Sub

Public Sub OnTimer(ByVal source As Object, ByVal e As Timers.ElapsedEventArgs)

Main() 'fill WH & PK arrays

End Sub

End Class

When i executed the following code, my compiled exe constantly grows 4K each time the timer is executed. Apperently, .net garbage collection does not work on unmanaged code? If I replace this line:

Dim test As Object = CreateObject("AutoItX3.Control")

with this:

Dim test As integer = 0

the problem is solved. Thus, it is fair to say that I am constantly creating AutoItX3 type objects and the memory is not be reassigned after the sub routine finishes execution. I am not sure how I should fix this problem. Any ideas? thx!

Share this post


Link to post
Share on other sites



VB.Net code

Public Class Form1

Public aTimer As System.Timers.Timer

Public Sub Main()

Dim test As Object = CreateObject("AutoItX3.Control")

End Sub

Public Sub Start()

aTimer = New System.Timers.Timer

AddHandler aTimer.Elapsed, AddressOf OnTimer

aTimer.Interval = 2500

aTimer.Enabled = True

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Start()

End Sub

Public Sub OnTimer(ByVal source As Object, ByVal e As Timers.ElapsedEventArgs)

Main() 'fill WH & PK arrays

End Sub

End Class

When i executed the following code, my compiled exe constantly grows 4K each time the timer is executed. Apperently, .net garbage collection does not work on unmanaged code? If I replace this line:

Dim test As Object = CreateObject("AutoItX3.Control")

with this:

Dim test As integer = 0

the problem is solved. Thus, it is fair to say that I am constantly creating AutoItX3 type objects and the memory is not be reassigned after the sub routine finishes execution. I am not sure how I should fix this problem. Any ideas? thx!

I was able to solve the problem by doing this:

Public oAutoIt = CreateObject("AutoItX3.Control")

CODE GOES HERE...

oAutoIt = Nothing

Share this post


Link to post
Share on other sites

I was able to solve the problem by doing this:

Public oAutoIt = CreateObject("AutoItX3.Control")

CODE GOES HERE...

oAutoIt = Nothing

May I also suggest this:

Public oAutoIt as New AutoItX3Lib.AutoItX3

Wouldnt you prefer early binding and the intellisense support!?!?!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0