<span id="Label3"></p> <ol> <ol> <li>How to ensure that many people develop a memory leak check <span style="font-family: Cambria;">.</span> How do I locate a memory leak?</li> </ol> </ol><p class="p15"><p class="p15">1> <span style="font-family: Cambria;"></span> <span style="font-family: 宋体;">Static analysis of code using ANALYZE (detects potential memory Leaks)</span></p></p><p class="p15"><p class="p15">2> through <span style="font-family: Cambria;">leak</span> <span style="font-family: 宋体;">check for memory leaks during program run</span></p></p><p class="p15"><p class="p15">3> in order to avoid unnecessary trouble <span style="font-family: Cambria;">,</span> <span style="font-family: 宋体;">multi-person development when possible to use</span> <span style="font-family: Cambria;">ARC</span></p></p><p class="p15"><p class="p15"></p></p><p class="p0"><p class="p0">2<span style="font-family: 宋体;">. How to do the singleton mode in the case of non-automatic memory management</span> <span style="font-family: Cambria;">.</span></p></p><p class="p0"><p class="p0">Basic steps to create a singleton design pattern ·</p></p><p class="p0"><p class="p0">> <span style="font-family: 宋体;">declares a static instance of a single object</span> <span style="font-family: 宋体;">and initializes</span> <span style="font-family: Cambria;">it to</span> <span style="font-family: Cambria;">nil</span><span style="font-family: 宋体;">. </span></p></p><p class="p0"><p class="p0">> <span style="font-family: 宋体;">Create a class factory method</span> <span style="font-family: Cambria;">that</span> <span style="font-family: 宋体;">generates an instance of a</span> class if <span style="font-family: 宋体;">and only if the instance of the class is</span> <span style="font-family: Cambria;">nil</span></p></p><p class="p0"><p class="p0">><span style="font-family: arial;"> implement </span> <span style="font-family:cambria;">nscopying </span> <span style="font-family: Song body;" "> protocol </span> <span style="font-family:cambria;">, </span> <span style="font-family: song body;"> overwrite </span> <span style="font-family:cambria;">allocwithzone: </span> <span style="font-family: The song body;"> method </span> <span style="font-family:cambria;" , < span> <span style="font-family: The song body;"> Ensure that users are assigned and initializing objects directly </span> <span style="font-family:cambria;" , < span> <span style="font-family: The song body;"> Not another object will be produced . </span> </span></span></p></p><p class="p0"><p class="p0">> <span style="font-family: 宋体;">cover</span> <span style="font-family: Cambria;">release</span><span style="font-family: 宋体;">,</span><span style="font-family: Cambria;">autorelease</span><span style="font-family: 宋体;">,</span><span style="font-family: Cambria;">retain</span><span style="font-family: 宋体;">,</span> <span style="font-family: Cambria;"> The Retaincount</span> <span style="font-family: 宋体;">method</span> <span style="font-family: Cambria;">is</span> used <span style="font-family: 宋体;">to ensure the status of the Singleton. </span></p></p><p class="p0"><p class="p0">> <span style="font-family: 宋体;">in a multithreaded environment</span> <span style="font-family: Cambria;">,</span> <span style="font-family: 宋体;">Note the use</span> <span style="font-family: Cambria;">of @synchronized</span> <span style="font-family: 宋体;">keywords or</span> <span style="font-family: Cambria;">GCD,</span> <span style="font-family: 宋体;"> Make sure that the static instance is created and initialized correctly. </span></p></p><p class="p0"><p class="p0"></p></p><p class="p0"><p class="p0">3<span style="font-family: 宋体;">. The default for class methods (static Methods) is</span> <span style="font-family: Cambria;">autorelease</span> <span style="font-family: 宋体;">. Will all class methods be like this? </span></p></p><p class="p0"><p class="p0">The 1> <span style="font-family: 宋体;">system comes with a large number of methods that return objects</span> <span style="font-family: Cambria;">,</span> <span style="font-family: 宋体;">all</span> of which are autorelease</p></p><p class="p0"><p class="p0"></p></p><p class="p0"><p class="p0">4<span style="font-family: 宋体;">. </span> <span style="font-family: 宋体;">What is the difference between the usage</span> of <span style="font-family: Cambria;">block</span> <span style="font-family: 宋体;">in</span> <span style="font-family: Cambria;">ARC</span> <span style="font-family: 宋体;"></span> and <span style="font-family: Cambria;">MRC</span> <span style="font-family: Cambria;">,</span> <span style="font-family: 宋体;"> What to pay attention to</span></p></p><p class="p0"><p class="p0">1. <span style="font-family: 宋体;">either</span> <span style="font-family: Cambria;">ARC</span> <span style="font-family: 宋体;">or</span> <span style="font-family: Cambria;">MRC</span><span style="font-family: 宋体;">, the</span><span style="font-family: Cambria;">block</span> <span style="font-family: 宋体;">should be held with</span> a <span style="font-family: Cambria;">copy</span> <span style="font-family: 宋体;">operation </span></p></p><p class="p0"><p class="p0"></p></p> <ol> <ol> <li>Care should be taken to avoid circular references</li> </ol> </ol><p class="p15"><p class="p15">1> ARC: __weak<span style="font-family: 宋体;">,</span><span style="font-family: Cambria;">__unscafe_unretained</span></p></p><p class="p15"><p class="p15">2> Mrc:__block</p></p><p class="p0"><p class="p0"></p></p><p class="p0"><p class="p0">5<span style="font-family: 宋体;">. </span>under what circumstances will a memory leak and memory overflow occur?</p></p><p class="p0"><p class="p0">1> <span style="font-family: 宋体;">Memory Leak: The release is not Released. Memory leaks accumulate a serious consequence, no matter how much memory</span> <span style="font-family: Arial;">,</span> <span style="font-family: 宋体;">sooner or later, will be occupied by light. Memory leaks will eventually cause memory overflow! </span></p></p><p class="p0"><p class="p0">2> <span style="font-family: 宋体;">Memory Overflow: full memory, not enough</span></p></p><p class="p0"><p class="p0">When the program is applying for memory, there is not enough memory space for it to use, and <span style="font-family: Arial;"></span><span style="font-family: 宋体;">an out</span> of memories appears; For example <span style="font-family: Arial;">, an int</span> was applied, <span style="font-family: 宋体;">but it was saved</span> <span style="font-family: Arial;">long</span> <span style="font-family: 宋体;"> To save the number, that is the memory overflow. </span></p></p><p class="p0"><p class="p0"></p></p><p class="p0"><p class="p0">6<span style="font-family: 宋体;">. </span>[nsarray arraywithobject:<id>] Does this method need to be freed after adding an object?</p></p><p class="p0"><p class="p0">This object is not required to be placed in the Auto-release pool</p></p><p class="p0"><p class="p0"></p></p><p class="p0"><p class="p0">7<span style="font-family: 宋体;">. </span> <span style="font-family: Cambria;"></span> <span style="font-family: 宋体;">is there a memory leak when parsing the Json data and parsing the data? Some words how to solve</span></p></p><p class="p15"><p class="p15">1> JSON <span style="font-family: 宋体;">Parsing scheme</span></p></p><p class="p15"><p class="p15">L Sbjson</p></p><p class="p15"><p class="p15">L Jsonkit</p></p><p class="p15"><p class="p15">L Nsjsonserialization</p></p><p class="p0"><p class="p0"></p></p><p class="p15"><p class="p15">2> memory leaks <span style="font-family: Cambria;">?</span></p></p><p class="p0"><p class="p0"></p></p><p class="p0"><p class="p0">8. <span style="font-family: 宋体;">Automatic release of the pool bottom how to implement</span></p></p><p class="p0"><p class="p0">The Auto-free pool is implemented as a stack <span style="font-family: Cambria;">:</span> when <span style="font-family: 宋体;">you create a new Auto-free pool, it is added to the top of the Stack. When an object receives a send</span> <span style="font-family: Cambria;">autorelease</span> <span style="font-family: 宋体;">message</span> <span style="font-family: Cambria;">,</span> <span style="font-family: 宋体;">It is added to the current Thread's top-of-stack auto-release pool</span> <span style="font-family: Cambria;">,</span> when the <span style="font-family: 宋体;">auto-free pool is recycled </span> <span style="font-family: Cambria;">,</span> <span style="font-family: 宋体;">They are removed from the stack</span> <span style="font-family: Cambria;">,</span> <span style="font-family: 宋体;">and all objects inside the pool are given a</span> <span style="font-family: Cambria;">release</span> <span style="font-family: 宋体;">operation</span> <span style="font-family: Cambria;">.</span></p></p><p class="p0"><p class="p0">9 <span style="font-family: 宋体;">Increase</span> The <span style="font-family: 宋体;">memory consumption behavior of</span> an <span style="font-family: Cambria;">APP</span> :</p></p><p class="p0"><p class="p0">Create an OC <span style="font-family: 宋体;">object;</span></p></p><p class="p0"><p class="p0">Define a variable;</p></p><p class="p0"><p class="p0">Call a function or method</p></p><p class="p0"><p class="p0">Memory is too large, the system may force the <span style="font-family: Cambria;">APP</span>to close<span style="font-family: 宋体;">. The phenomenon of Flash-back is</span> that the <span style="font-family: Cambria;">APP</span> <span style="font-family: 宋体;">suddenly crashes and exits meaning, affecting the user experience. </span></p></p><p class="p0"><p class="p0">Only OC <span style="font-family: 宋体;">objects require the essential reasons for memory Management:</span></p></p><p class="p0"><p class="p0">OC <span style="font-family: 宋体;">objects stored in the heap, non-</span> <span style="font-family: Cambria;">oc</span> <span style="font-family: 宋体;">objects are generally placed inside the stack, the system will automatically recycle stack memory</span></p></p><p><p>iOS Technology interview 02: memory management</p></p></span>
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