Summary of bug fixing on the refresh interface of the refresh tower defense 2 (cocos2dx memory management mechanism)

Source: Internet
Author: User

The game recharge interface is always intermittent, and the debug debugging breakpoint is always broken in a deep position, and there is no error.

 

Later, a breakpoint was broken at the place where the program created a prompt image, so I checked the code and found the problem.

 

The error code before modification:

 

1. Create the code for the prompt:

M_loading = new netloading (this, callfunc_selector (iapshoplayer: downingupdate); // m_loading reference count is 1

M_loading-> setposition (CCP (1139/2. 0f, 640366f/2.0f ));

M_loading-> autorelease (); // m_loading is added to the automatic management pool.
Addchild (m_loading, 1000 );

2. Remove the prompt code

If (m_loading! = NULL)
{
If (m_loading-> getparent ()! = NULL)
{
Removechild (m_loading, true); // m_loading reference count minus one, 0, releases this object
}
M_loading-> release (); // The m_loading object does not exist and an error is returned.
M_loading = NULL;
}

Error cause:

M_loading-> autorelease ();

The object has adopted an automatic management mechanism, so you do not need to manually call release () to reduce the reference count by 1.

Removechild (m_loading, true); after the code is executed, the automatic management mechanism determines that the object is no longer in use. Therefore, the m_loading reference count is reduced by one. At this time, the reference count of m_loading is 0 and released.

Therefore, an error is returned when m_loading-> release () is executed.

 

Summary: in the future, the object memory management will always be careful. The memory management solution either uses manual management or automatic management, but cannot be used at the same time. (Which memory management method is used depends on the actual situation)

 

Cocos2dx memory management mechanism reference: http://blog.csdn.net/ring0hx/article/details/7946397

 

refresh bug fixing summary on the refresh interface of the anti-DDoS Pro 2 (cocos2dx Memory Management Mechanism)

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.