Reduces the application's 11 MB memory usage to 500 KB

Source: Internet
Author: User

Recently solved a problem-reducing memory usage. However, this method can only be used in WINXP and Win2k, without displaying that the main form is always running.ProgramBest. In the past, the program used 11 MB of memory. I used the dynamic window creation method to reduce the size by less than 100 kb. After applying this method, the memory usage was only 496 kb. Put the following process in a timer and execute it every other time, for example, 5 seconds.
{
**********
* Clear memory
* From muse2008
**********
}
Procedure clearmemory;
Begin
If win32platform = ver_platform_win32_nt then
Begin
Setprocessworkingsetsize (getcurrentprocess, $ ffffffff, $ ffffffff );
Application. processmessages;
End;
End;
 

About setprocessworkingsetsize and memory release

In applications, some functions are often used to release memory. In fact, the memory operation functions should be used with caution. For example, the setprocessworkingsetsize that people often think of is actually for Windows, the system will automatically release the memory when the program is idle (such as the program is minimized). When you release the memory, it will often cause some inexplicable memory errors, this causes unstable applications and systems.

Move physical memory usage to virtual memory
In fact, you can also try to minimize a program to the taskbar, and then look at the task manager. No, the actual memory occupied by your program is suddenly reduced, it seems that I don't have any way to compress the memory, but the operating system itself has this mechanism, that is, when the program is not in use (minimized), the operating system will call some commands, memory occupied by the program

Move to virtual memory, retain only a small portion of the GeneralCode

So we can see that the memory usage is reduced at once.

Setprocessworkingsetsize
Use this function to set the minimum and maximum runtime space of the application, and only reserve the required memory. When the application is idle or the system memory is too low, the operating system will automatically call this mechanism to set the application memory. Applications can also use virtuallock to lock a certain range of memory from being released by the system. In fact, using this function does not improve performance or actually save memory. Because it only temporarily moves the memory occupied by the application to the virtual memory. Once the application is activated or has an operation request, the memory will be occupied again. If you use this method to set the memory occupied by the program, the system performance may be reduced to some extent because the system needs to frequently perform page exchanges between the memory and the hard disk. The reason for keeping the Minimum Memory is that the timer is used and the operation is not stopped. Therefore, the performance can be imagined. Although the illusion of small memory is met, it is indeed a disaster for the system.

This function is not all right,
1. When our application is just loaded, you can use this operation once to put the code not required in the loading process into the virtual memory. In this way, after the program is loaded, maintain a large amount of available memory.
2. When the program runs for a certain period of time or the program is about to be idle, you can use this command to swap the occupied memory to the virtual memory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.