OpenGL Memory leakage-Main Loop Function ()

Source: Internet
Author: User

 

In the Win32 console, the standard OpenGL process is as follows:
Int main (INT argc, char * argv [])
{

Gluinitwindowsize (500,250 );
Gluinitwindowposition (140,140 );
Fig );
Gluinit (& argc, argv );

 

 

Valley createwindow ("Demo ");

 

Glclearcolor (1.0, 1.0, 1.0, 1.0 );

Gludisplayfunc (Display );
Glureshapefunc (reshape );

 

Glumousefunc (Mouse );
Glumotionfunc (motion );

 

Glukeyboardfunc (key );

 

Glumainloop ();

Return 0;

}

 

In the dialog box program of MFC, using such a process may cause memory leakage. The reason is thatGLutmainloop ()The normal process of the system is blocked. After the window created by the glucreatewindow () is closed, the glumainloop () directly exits the program with exit (0) instead of executing the statements after the glumainloop, this makes the release and Resource Recycling of some classes impossible, resulting in Memory leakage. There are three ways to correct this problem:

1. Use gluleavemainloop () instead of glumainloop ().

2. process the exit (0) part of the code.

3. Set the following parameters before applying the Keyword:

Glusetoption (maid, FIG );

Then, the following code is executed.

The above method can effectively deal with Memory leakage caused by glumainloop!

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.