Cocos2d-x Development --- memory detection, cocos2d-x Development ---

Source: Internet
Author: User

Cocos2d-x Development --- memory detection, cocos2d-x Development ---
During the interviews over the past few days, the interviewer will ask me how to cope with memory detection during game development and how to monitor the program for Memory leakage. I have not paid serious attention to this issue during the development process (not to mention not focusing on program memory leakage, but to deliberately thinking about how to monitor it ), because the previous company used xcode development tools, which provided performance monitoring tools, usually used this tool, may not be too concerned about this.
Because the interviewer asked me a lot about this, I felt that I really needed to pay more attention to some basic issues in the program development process, so I sorted out what I knew.
Mac: xcode is used for development. When you run a simulator or perform real-machine debugging, the upper left corner of xcode displays information such as cpu usage and memory usage. The simulator displays the information of the computer, while the real machine debugging displays the information of the real machine.
On Windows: When VS is used for development, a software called Visual Leak Detector detects Memory leakage. This software was seen a long time ago when I was reading a blog on the Internet. It seems that the detection information is displayed only after the program is debugged, because it was used for a long time ago, it may be a bit difficult to remember. Another way is to debug on your computer and start the windows Task Manager, in the process, the memory and cpu usage of the running program are monitored in real time. When the memory usage is abnormal, you can perform targeted troubleshooting.
The above is what I know now.
I. How to optimize the memory usage of cocos2dx (advanced)

P = 93 I. Memory optimization principle in order to optimize the application memory, you should know what consumes most of your application's memory. The answer is Texture )! It occupies almost 90% of the application memory. We should try our best to reduce the texture memory usage of our application, otherwise our application process may be killed by the system. Here we provide two general guidelines for cocos2dx game memory optimization to reduce memory warnings. 1) understand the bottleneck, and then solve what kind of texture consumes most of the application's memory? Or how much memory does these textures consume? You do not need to perform manual computation or speculation. Here we have a tool. It is Apple's development tool-Allocations & Leaks. In xcode, you long press the Run button and select Profile to start these two tools. Here we have one: You can use the Allocation tool to calculate the memory usage of your application and view the memory leakage. You can also use some code to obtain useful information about the game memory usage. Run the following code: CCTextureCache: sharedTextureCache ()-> dumpCachedTextureInfo (); as follows: when you call the code and run your game in DEBUG mode, in your xcode console window, you will see some formatted log information Cocos2d: cocos2d: "cc_fps_images" rc = 5 id = 3 256x32 @ 16 bpp => 16 KB Cocos2d: cocos2d: "XXX/hd/actor. pvr. ccz "rc = 1059 id = 4 2048x2048 @ 32 bpp => 16384 KB Cocos2d: cocos2d: CCTextureCache dumpDebugInfo: 2 textures, for 16400 KB (16.02 MB) these logs show the texture name, reference number, id, The size and the bit value of the pixel. The most important thing is that it shows the memory usage. As shown above, cc_fps_images consumes 16 KB, and actor. pvr. ccz consumes 16 MB of memory. 2) do not over-optimize this is a regular optimization rule. When optimizing the memory, you should make a trade-off. Because sometimes the image quality is opposite to the image memory usage. Therefore, do not over-optimize it. Ii. Memory optimization level here we divide cocos2dx memory optimization into three levels. At each level, we have different points of view and some changes in strategies. 1. The cocos2dx client level is the most important optimization level we can consider. Because we develop games on the cocos2dx engine, the engine provides many optional optimization solutions. At this level, we can do the most work. First, let's take a look at texture optimization. In order to optimize the texture memory usage, we must know what factors affect the memory usage. Three factors affect texture memory usage. Texture format (compressed or non-compressed), color, and size. We can use PVR format textures to reduce memory usage. The most recommended texture format is pvr. ccz. The higher the bit value of each color, the better the image quality. But it also consumes a lot of memory. Then we use the color depth of RGBA4444 texture instead of RBGA8888, which will consume half of the memory. We will also find that large textures will also cause memory-related problems. So you 'd better use a moderate size. Next, let's do something about sound. There are three factors that affect file memory usage. It is the audio file format, bit rate, and sample rate. We most want the mp3 format for audio files. Because it is supported by both android and ios. It is also compressed and the hardware is accelerated. Make sure that the size of your background music file is kb. The simplest way is to reduce the playing time of background music and... the remaining full text>

Using cocos2d-x developed a small game, _ bullet and bullet collision detection, get sprite texture size occasionally reported error, as shown below

This is the access to invalid memory... If you're sure it was a crash in your lap .. Check whether the memory pointed to by your tex is valid ....

Related Article

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.