memory leak!!!help!!!

S

sheng shan

Hi everyone,

I have been in trouble really all these days,the memory leak problem
of CF is killing me.Below are the details:

target:geode x86 cpu with ce .net 4.2(CF sp1 installed)
application:developed in vb.net(integrated in VS2003).about 14 forms
switched forward and backward(interacted with user),compiled and built
are successful,but after running for not more than 2 hours in the target
it consumed all the available memory of ce .net and made the app stopped
exceptionally.I searched all the forum and I am aware it's the bug of
CF,even CF SP1 didn't solved the problem. I tried all the suggestion I
could find(such as gc.collect,formxxx.showdialog()
formxxx=nothing),but all of them don't work,I am expecting the sp2 which
may have solved the memory leak problem.but before the sp2 is
released,what can I do?are there any other ways to solved the problem?
any hint will be appreciated very very much!!
 
C

Chris Tacke, eMVP

I'm not aware of any such memory leak in the CF. Are you properly disposing
your objects (especially Forms)?
 
M

Martin Asselhoff

Let me summarize your problem.
You let the user of your application to switch between 14 Forms you created.
After an amount of time your application fills all the available memory on
device, so that the application can not proceed.

It's just an idea.

It sounds like each time user switches to the next Form, your application
creates a new object of the matching form and does not dispose the object of
the old form.

Can you give me an example of code, how do you switch between Forms.

Is it possible to switch between them by reference? Create your Forms once
and then switch by reference.

Of course the problem could be on a completely different place. It depends
on what your Forms do.
For example access to a database or to any other ressource by one of your
forms can also cause a memory leak.
 
S

sheng shan

Hi Chris Tacke,
Thank you for your replying.
yes, I did dispose the forms properly.like below:
formxxx.dispose
BTW:
I used a user-built dll in the application.of course first I declared
it in a moudle.the functions and the sub of the dll just works fine.it's
declared just like this:
<System.Runtime.InteropServices.DllImport("dualrama.dll",
SetLastError:=False)> Public Sub RamAMapAddress(ByVal PhyAddress As
Integer)
End Sub
I used virtualalloc,virtualcopy only once in this dll,maybe that's one
of the reasons?but how could this happening(even if it's because that
the allocated mem is not freed,it's address should be stable while the
app is running)?
any suggestion?
if somebody is interested I could post the dll source file.
 
S

sheng shan

I tried many methods(none of them does work) to avoid the memory
leak,one of them is just like Mr Martin Asselhoff suggested:Create the
Forms once and then switch by reference,another way is dispose the old
one after create a new one.here is part of the code:
in the startup form(form1):
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
....
mymain = New main

mylcgk1 = New lcgk1
mylcgk2 = New lcgk2
mypromain = New promain
mypromc = New promc
myproact = New proact
myproairc = New proairc
myproaxt = New proaxt
myprobur = New probur
myprocont = New procont
mypropnu = New propnu
mymain.Show()
Me.Hide() 'form1 is the main form of the app
'could not be disposed

End Sub

in one of the created forms--mymain:

......
Private Sub main_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load


Cursor.Hide()
TextBox3.Height = 210
TextBox1.Height = 210
TextBox12.Height = 105
TextBox13.Height = 105
TextBox23.Height = 108
......
End Sub

Protected Overrides Sub OnKeyDown(ByVal e As
System.Windows.Forms.KeyEventArgs)
Select Case e.KeyCode
Case Keys.End
Application.Exit()
Case 48
mylcgk1.Show()
mymain.Hide()
Case 49
mypromain.Show()
Me.Hide()

Case 49
' myprobur = New probur
myprobur.Show()
'mypromain.Dispose()
'mypromain = Nothing
''gc.collect()
'mypromc.Show()
Me.Hide()
''gc.collect()
Case 50
'mypropnu = New propnu
mypropnu.Show()
' mypromain.Dispose()
' mypromain = Nothing
''gc.collect()
'mypromc.Show()
Me.Hide()
''gc.collect()
Case 51
'myproairc = New proairc
myproairc.Show()
'mypromain.Dispose()
'mypromain = Nothing
''gc.collect()
'mypromc.Show()
Me.Hide()
''gc.collect()
Case 52
'myprocont = New procont
myprocont.Show()
'mypromain.Dispose()
'mypromain = Nothing
''gc.collect()
'mypromc.Show()
Me.Hide()
''gc.collect()
Case 53
'myproact = New proact
myproact.Show()
'mypromain.Dispose()
'mypromain = Nothing
''gc.collect()
'mypromc.Show()
Me.Hide()
''gc.collect()
Case 54
'If ConnectFlag = True Then
'Form26_r.Show
'Form5.Visible = False
'Else
'myproaxt = New proaxt
myproaxt.Show()
'mypromain.Dispose()
'mypromain = Nothing
''gc.collect()
'mypromc.Show()
Me.Hide()
''gc.collect()

End Select
End Sub
......

created forms are switched if user pressed the 0-9 buttons
if these codes are not enough,shall post the dll code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top