Saturday, December 21, 2013

Several related issues and memory cocos2d own summary

posts by supershiben edited 2011-08-20 11:56:00
Yesterday, for the first time the program runs into the real machine, the result after running 2,3 seconds, direct crash. What was scared at the time, and soon pay program, and use the simulator to run before all good, Zage aiming a machine to die ah? In a search online, only to find that the memory had gone wrong. So check out the next memory footprint, enlightened, a look surprised, initial program load memory have 360m! , Play a few off, the memory immediately Biao to 500m. This can be horrible. So he spent a whole day, carefully studied cocos2d memory problems. After a series of optimization, the maximum memory usage down to only 190M or so, this solved the problem of people frantic. Here are a few points and finishing my memory-related, we want to encounter the same memory problems to help a friend!

1. Caution big picture
Algorithms for image memory size occupied by a 1024 * 1024 picture, loaded into the texture, the occupying 1024 * 1024 * 4 (4m) memory. After rendering a wizard, and texture will occupy the same memory, so this picture is the total memory occupied by 8m. (Draw wizard when it comes to drawing this picture wizard to calculate the size of memory, such as a 28 * 28 area only painting this picture of the size, you only need a 32 * 32 * 4 = 4K memory size) < br />
2 picture size is very important
There is a large picture size traps, 1024 and 1025 * 1024 * 1025 picture seems almost, in fact, a far cry from the memory footprint, because cocos2d is based on the size of the image N adaptive power of 2, so 1025 * 1025 After the image is loaded actual texture size is 2048 * 2048, will occupy 8m texture memory! 1024 1024 * 2 times of that picture. So encountered a similar size pictures, it is best to use the PS adjustment under size.

3 Use Tools to view memory usage
Leaks that comes with xcode tools can easily view the situation and find the program occupies memory leak stack.

4 Check the object has not been released
When the code is more complex when you have to worry about some of the objects in other places you might not pay attention to retain the reference count, leading to the release method when you use this object, and not the actual object dealloc away. So you have to go through marked breakpoints or output log in dealloc method of each object, to verify whether the object really was released.

5 Using real test
Generally in the emulator, because the computer memory itself is large, so in this case, even if your memory for the program is high, it will not receive any warnings and exceptions. But if the real test conducted on iphone or ipad, because the device is less available memory, so most of the memory problems will be exposed. So advancing the real test is necessary.
(In the real machine, the program will greatly enhance the operating efficiency in the simulator game less than 10 frames, put on a real machine is actually 60 full, mac mini performance really dish ah!)

6 memory warning.
When the machine memory when tight, will give the program a memory warning message. This message is divided into two levels 1 and 2, level 1, when basically fine. Level 2, when we should note, then usually far away from the crash (program memory footprint of around 350M will generally receive a warning level 2). If the program's memory usage exceeds 400M, then the program will basically be directly killed by the operating system, the performance of the ipad is the program to exit. And this time the program will not print any help you check the log!


The stunning technological Zhang
QQ: 454882367
MSN: supershiben@hotmail.com
2011/8/20

Reply:
nice stay names doing ah?
Reply:
Thank you for sharing
Reply:
With a sprite sheet texture together, can effectively reduce the memory.
In addition, "rendered after the wizard, and texture will occupy the same memory, so this picture is occupied by the total memory 8m", so say no. Textures only take up memory.
Also, "In the real machine, the program will greatly enhance the operational efficiency in the simulator game less than 10 frames, put on a real machine is actually 60 full" real machine simulates the way, that is with x86 running arm, with the course running desktop cpu speed is not the same. This simulation mode that differs from android.
If the game has music, then the memory usage is quite large
Reply:


Thanks for sharing



Reply:
Good. . . .
Reply:
Hello,
Has been added to your QQ, together we progress ...
Reply:
Nice post, learning

No comments:

Post a Comment