Memory Leak using Flash Object

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
 
Even if you have called the garbage collection that doesn't always mean that the common language runtime will release all the memory it has used. There, to my knowledge, is no way of forcing then CLR to do this. But rest assured that it will get around to it, in it's own time.
 
This is the problem though, it never gets round to it, you could leave the app running all day and the machine would simply run out of memory. I'm convinced this is becuase the flash object is a COM component. I have searched the web and found nothing that can explain this.
 
Well i ran an app very similar to your one and i couldn't notice anything like memory leak or something. Btw, it really doesn't matter cuz it is COM object. I'm using COM objects all the time and i am also convinced that your problem is not caused by that. Can you send the flash movie please? i want to take a look of it ... maybe it is the causer (bug like infinite loop or something)

Regards ;)
 
Back
Top