Kristian73

Hi world,

I've a problem related of lack of memory.

Running application the memory is OK.

When I start to navigate inside the forms the momory continue increasing and an error "Out of memory" is

generated.

I thought the problem was the "not disposed bitmaps" so,

when I close the forms I'm disposing all the bitmap used but the problem have not solved.

In the application I use many System.Windows.Forms.Timer.

Sombody know if the not correct use of "Timer" can create memory problem

When I close the forms I'm setting:

Timer.Enable = False

Timer.Dispose()

for all the Timer used.

Thanks




Re: .NET Compact Framework Out of memory exception on WinCE5.0

Kristian73

Hi world,

I've a problem related of lack of memory.

Running application the memory is OK.

When I start to navigate inside the forms the momory continue increasing and an error "Out of memory" is

generated.

I thought the problem was the "not disposed bitmaps" so,

when I close the forms I'm disposing all the bitmap used but the problem have not solved.

In the application I use many System.Windows.Forms.Timer.

Sombody know if the not correct use of "Timer" can create memory problem

When I close the forms I'm setting:

Timer.Enable = False

Timer.Dispose()

for all the Timer used.

Thanks






Re: .NET Compact Framework Out of memory exception on WinCE5.0

Kristian73

Hi world,

I've a problem related of lack of memory.

Running application the memory is OK.

When I start to navigate inside the forms the momory continue increasing and an error "Out of memory" is

generated.

I thought the problem was the "not disposed bitmaps" so,

when I close the forms I'm disposing all the bitmap used but the problem have not solved.

In the application I use many System.Windows.Forms.Timer.

Sombody know if the not correct use of "Timer" can create memory problem

When I close the forms I'm setting:

Timer.Enable = False

Timer.Dispose()

for all the Timer used.

Thanks






Re: .NET Compact Framework Out of memory exception on WinCE5.0

Rik78

Hi

My experience is that you need to call GC.Collect() at appropriate times in your application.

You shouldn't call it in a tight loop, but in close events and at the end of doing things.

If you haven't already you should build a memory manager to keep track of memory available, making memory statistics etc

-Raymond






Re: .NET Compact Framework Out of memory exception on WinCE5.0

Kristian73

First thanks for answer.

I already do GC.Collect when close the forms.

How can I make a memory manager

Bye






Re: .NET Compact Framework Out of memory exception on WinCE5.0

Ilya Tumanov

You have a memory leak which you should find and eliminate; forcing GC won¡¯t help you at all.

Finding leaks is not easy. I would suggest using ¡°divide and conquer¡± approach: remove significant part of your application and run the rest, see if memory is leaking and at what rate. You can call GC.GetTotalMemory(true) to monitor managed memory allocation and P/Invoke GlobalMemoryStatus() (please search if you need a signature) to include native allocation as well. If leak stopped or reduced part of the code you¡¯ve eliminated was leaking. Divide that part to find specific parts.

Things to watch for:

- Not calling Dispose() on anything what has it (Bitmaps, forms, controls, components, SQL CE and SQL Client objects and so on).

- Complex data binding: make sure to set DataSource of list controls and DataGrid to null/Nothing as soon as you no longer need them.

- Native interop: make sure to release memory allocated on the native side or unpin objects pinned on managed side.






Re: .NET Compact Framework Out of memory exception on WinCE5.0

Rik78

In my latest application I had a memory leak.

The memory went down after doing a sql search, and I'm sure i disposed the objects and had them set to nothing.

So after 50 searchs or so, it gave me an exception with no message in it, and it broke my sql ce database just to be sure Smile

I put a GC.Collect() after the search and the memory did not drop anymore.

After hunting down this problem I started not to rely on .net and automatic garbage collection...

You can get available program memory with the native "GetSystemMemoryDivision", I think you need to use the third parameter, then divide that by 1012 to get the number of bytes.

I'm also using "SetSystemMemoryDivison" if memory is getting low, or if I know at program startup how much memory the application needs.

-Raymond






Re: .NET Compact Framework Out of memory exception on WinCE5.0

Kristian73

Thanks very much!!!!!

The problem was that I did not dispose Forms and DataGrid.

I solved problem adding "Me.Dispose" after Close instruction:

Me.Close()

Me.Dispose()

But now I've other problem, the problem is the follow:

If I close a child form (opened with ShowDialog) using only Close() istruction, the OS do the control to the "parent Form", and this is what I need.

If I close a child form (opened with ShowDialog) using Close() and after Dispose() istructions, the OS do the control to the "File manager application" and my "parent Form" disappear. So I've to searh my "parent Form" in the task bar and click it to make it visible again.

Somebody can help

Thanks in advance

Kristian






Re: .NET Compact Framework Out of memory exception on WinCE5.0

Rik78

Hi

The Dispose() call shouldnt' be in the form you are disposing, but after the ShowDialog call in the parent form.

Also check if you have any unnecessary hide or show statements, or dialogresults on any buttons which collides with what you are trying to do.

-Raymond






Re: .NET Compact Framework Out of memory exception on WinCE5.0

Kristian73

Hi Raymond,

your answer was very useful for me.

Thanks very much