davenaylor2000
Member
- Joined
- Dec 1, 2005
- Messages
- 7
- Programming Experience
- 1-3
Hello, here is the situation.
I have a very large application that has a memory leak within it. This application loads many instances of flash objects and even though these objects are been killed the application has a quite severe memory leak.
In order to prove this was flash i built a very small application.
This test App loads a form with two buttons
The first button creates 50 instances of a form.
this form loads a flash SWF file on its load, this is loaded in the AxShockwaveFlashObjects.AxShockwave Flash container.
The second button on the main form destroys all 50 forms.
when running this application it starts by using about 19 megs of ram
after loading all the form this goes upto 54 megs of ram
when i kill the forms i dispose of them and set them to nothing
i also dispose of the flash object and set that to nothing on the form closing event
when all forms are closed i run the garbage collector.
The memory now used by the App is arounf the 26 meg range. This is a gain of 7 meg everytime i create and kill the flash objects. if you can imagine in the larger scale application it would not take long for this memory to start impacting on the system as it uses more and more without releasing it.
Does anyone know why i cannot get rid of this 7 megs of ram?
I have included the code of my test app for your viewing.
Main Form
Private _FormCollection As Collection
Private Sub btnCreate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreate.Click
_FormCollection = New Collection
For i As Integer = 1 To 50
Dim aFlashForm As New Load_Flash
aFlashForm.Show()
_FormCollection.Add(aFlashForm)
Next
End Sub
Private Sub btnKill_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnKill.Click
For i As Integer = 1 To _FormCollection.Count
Dim aFlashForm As Load_Flash
aFlashForm = _FormCollection(i)
aFlashForm.Close()
aFlashForm.Dispose()
aFlashForm = Nothing
Next
_FormCollection = Nothing
Dim aLong As Long = GC.GetTotalMemory(True)
MsgBox(aLong)
GC.Collect()
aLong = GC.GetTotalMemory(True)
MsgBox(aLong)
GC.Collect()
aLong = GC.GetTotalMemory(True)
MsgBox(aLong)
GC.Collect()
aLong = GC.GetTotalMemory(True)
MsgBox(aLong)
GC.Collect()
aLong = GC.GetTotalMemory(True)
MsgBox(aLong)
GC.Collect()
aLong = GC.GetTotalMemory(True)
MsgBox(aLong)
End Sub
Flash loading form
Private Sub Load_Flash_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FlashMovie.LoadMovie(0, AppDomain.CurrentDomain.BaseDirectory & "test.swf")
End Sub
Private Sub Load_Flash_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Me.FlashMovie.Stop()
Me.FlashMovie.Dispose()
Me.FlashMovie = Nothing
End Sub
I have a very large application that has a memory leak within it. This application loads many instances of flash objects and even though these objects are been killed the application has a quite severe memory leak.
In order to prove this was flash i built a very small application.
This test App loads a form with two buttons
The first button creates 50 instances of a form.
this form loads a flash SWF file on its load, this is loaded in the AxShockwaveFlashObjects.AxShockwave Flash container.
The second button on the main form destroys all 50 forms.
when running this application it starts by using about 19 megs of ram
after loading all the form this goes upto 54 megs of ram
when i kill the forms i dispose of them and set them to nothing
i also dispose of the flash object and set that to nothing on the form closing event
when all forms are closed i run the garbage collector.
The memory now used by the App is arounf the 26 meg range. This is a gain of 7 meg everytime i create and kill the flash objects. if you can imagine in the larger scale application it would not take long for this memory to start impacting on the system as it uses more and more without releasing it.
Does anyone know why i cannot get rid of this 7 megs of ram?
I have included the code of my test app for your viewing.
Main Form
Private _FormCollection As Collection
Private Sub btnCreate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreate.Click
_FormCollection = New Collection
For i As Integer = 1 To 50
Dim aFlashForm As New Load_Flash
aFlashForm.Show()
_FormCollection.Add(aFlashForm)
Next
End Sub
Private Sub btnKill_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnKill.Click
For i As Integer = 1 To _FormCollection.Count
Dim aFlashForm As Load_Flash
aFlashForm = _FormCollection(i)
aFlashForm.Close()
aFlashForm.Dispose()
aFlashForm = Nothing
Next
_FormCollection = Nothing
Dim aLong As Long = GC.GetTotalMemory(True)
MsgBox(aLong)
GC.Collect()
aLong = GC.GetTotalMemory(True)
MsgBox(aLong)
GC.Collect()
aLong = GC.GetTotalMemory(True)
MsgBox(aLong)
GC.Collect()
aLong = GC.GetTotalMemory(True)
MsgBox(aLong)
GC.Collect()
aLong = GC.GetTotalMemory(True)
MsgBox(aLong)
GC.Collect()
aLong = GC.GetTotalMemory(True)
MsgBox(aLong)
End Sub
Flash loading form
Private Sub Load_Flash_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FlashMovie.LoadMovie(0, AppDomain.CurrentDomain.BaseDirectory & "test.swf")
End Sub
Private Sub Load_Flash_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Me.FlashMovie.Stop()
Me.FlashMovie.Dispose()
Me.FlashMovie = Nothing
End Sub