开发者

Google map memory usage on VB.Net form

I am using a Google map inside of vb.net application. The problem is that it keeps taking a memory space whenever I search a map on a web browser which is on a windows form . Even though I close the form, it is not disappeared from memory. The size of memory is just going up. That goes away when I close MDI form. What is the solution for this? How do I manage the memory problem?

-->Edited : One of out team member found the solution. It worked out pretty well. Just call the function whenever you want to do it. I used it on Form Closing event.

<DllImport("psapi.dll")> _
    Public Functi开发者_运维问答on EmptyWorkingSet(ByVal hProcess As IntPtr) As Boolean
    End Function

    <DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
    Public Function GetCurrentProcess() As IntPtr
    End Function

    Public Sub FreeMemory()
        EmptyWorkingSet(GetCurrentProcess())
    End Sub


Check out my answer to this question. I believe your best bet is to do some profiling.

I ran the trial version of ANTS memory profiler, against an app I was working on and the problem I discovered is outlined in this walthrough of how to use the tool (specifically the details around figures 10 - 15).

Basically, I was subscribing to some events on a form, but then not unsubscribing from them when the form was closed. This meant there was still a reference to the form and it (along with all it's controls and members) were never collected.

Maybe you have a similar situation, but your best bet is to look at the code in a profiler. It doesn't have to be this one (this is just the one I've used). It will certainly help you identify the root cause of your problem.


This is from the liberal garbage collection in .NET. If you're really concerned about memory, try this.

First, ensure that the objects you wish to remove have been disposed. If this is a Windows Form, this should be automatic.

Call System.GC.Collect(). You should see your memory usage decrease.


As a work around you could use an MDI parent and put your maps into MDI child forms opening up a new one each time (or periodically closing unused ones)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜