-
Hi. I am just wondering if some of you experienced programmers could leave some general tips on how to reduce the amount of memory an application uses. Some of my programs use way too much memory and I even got an 'out of memory' error today when unloading the application.
Thanks
Wengang
-
1. Try to avoid Controls and objects as much as possible, use UDT's instead of classmodules.
2. Don't have unnessesary variables, Use arrays instead of collections, Erase or optimize arrays that you don't need/have items you don't need
3. Don't use End, don't declare objects in standard modules without unloading them before termination
4. Don't terminate your app! That means don't click the stop button on vb toolbar
5. Be careful and delete all objects and device context when youre dealing with api's
6. Have resource meter loaded, and watch what's causing the resource loss.
-
Thanks Kedaman
Question:
If I declare a variable array like this
dim strVariable(10000) as string
Does that set aside memory for 10001 variables right away,
or just one, or does it set aside memory only as they are
assigned values?
And if that is the case (the first one), when you are coding, do you regularly use any method of releasing the memory space of the unassigned strings?
Thanks again.
-
the array will take up 24 bytes + the cumulative string lengths*2 + 22*10000 bytes
declare the array dynamic and you'll be able to erase it with erase statement :)=
-
What's a UDT?
This may sound stupid to you, but what is a UDT? User Defined Type?
-
-
Kedaman,
You said "Have resource meter loaded...".
What is that and where can I get it from?
Thanks.
-
Resource meter means the application which gives u all the details 'bout ur system dynamically. Like memory usage currently, cpu usage.
U can find this option under ur program- accessories- system tools option under win9x for WinNT, u have to just press Cltr + Alt + Del and go to performance tag.
Thats it.
Cheers
Latesh
-
Sorry, i was away this weekend and that last post was posted 2 mintues before my bus. Yep Resource meter should be at
C:\WINDOWS\RSRCMTR.EXE
but it only shows System, GDI and User Resources, but that's the ones you need to keep looking at while your running your app.