Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
desktop 64bit 16GB Win 10 Pro 21H2
laptop 64bit 16GB Win 10 Pro 22H2
The VB.net release exe runs properly on the desktop
Whether compiled on the laptop or running exe copied from desktop,
it get's out of memory error: g = Graphics.FromImage(Pages(pvDrawPage))
I have 6 1920x1080 3byte bitmaps in the collection Pages
Every second, I copy 1 to picturebox in panel in order to display.
In debug I can see the memory incrementing and eventual the error occurs.
Same for task manager.
On the desktop memory usage is stable - slightly going up and down and will run all day.

What I have tried:

Both computers using VS2022.
Moved development files and DLL's from desktop to laptop.
Builds are successful.
Posted
Updated 8-Feb-23 6:10am
Comments
Richard MacCutchan 8-Feb-23 11:10am    
You need to add some debug code to your application. It is impossible for anyone here to guess what is happening.
Dave Kreskowiak 8-Feb-23 11:59am    
It sounds like you've written some bad code that does not properly dispose of GDI objects, like Bitmap, Pen, Brush, Graphics, ...

Nobody can tell you what's wrong because nobody can see your code.
Member 15627495 8-Feb-23 12:08pm    
check if you're running in STA, or MTA.

to enhance and empower your apps, you'll have to handle more than one Thread.
GUIs forms are limited in memory and resources, when failing you reach the limit of a STA Apps ( max amount of memory reached ).

read about Thread, single Thread , Multi-Thread.

the same way as VB permit it, use for class '.dispose' or destroy vars with 'myVar = nothing'.

As it is .NET , you have the GC ( Garbage Collector ) as tool to empty ( for a gain ) all dead vars and clean the memory in use.

keywords :

- Garbage Collector
- Thread
- Task
- STA
- MTA
- dispose
- nothing
- erase
// It's all tools to manage VARS and processing codes without a bad memory handling.

the bug you have is random because of a bad memory use by your code.
Vars require to be destroy as soon you don't need them.
you said it , you see memory use increasing until it crash, proof the Thread is not safe, the code is unsecure.

1 solution

Since the memory usage keeps increasing, the chances are that you are creating things like bitmaps, Graphics objects, handles, and / or related classes which you are not releasing: an "Out of memory" error just means that a requested resource is not available as they are all in use - it's doesn't necessarily refer to actual memory! And since the error occurs on a Graphics creation line, that is most likely the culprit.

So start by wrapping the Graphics context in a using block:
C#
using (Graphics g = Graphics.FromImage(Pages(pvDrawPage)))
   {
   ...
   } // The context will be disposed here when it goes out of scope.

VB
Using g As Graphics = Graphics.FromImage(Pages(pvDrawPage))
   ...
End Using ' The context will be disposed here when it goes out of scope

Remember - a Graphics context wraps a Windows Handle - and they are scarce resources shared across the whole system. If your lappy is using a whole bunch of them already then it will run out before your desktop - but that will also run out eventually!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900