Domanda

I have noticed a a very bad behaviour in my code and I don't know how to solve this. I used the instruments tools in Xcode but still I cannot understand why the memory increases constantly at each loop.

In few words:

  1. I create a class derived from nsobject;
  2. I run a loop in which i create objects from this class and serialised them and save the url with the serialised object;
  3. At each loop the temporary object is released (i checked in dealloc func) but still the memory footprint increases.

I tested on the iPad and if the number of loop is very high, the memory gets lower and lower until the App crashes.

I have used the @autoreleasepool around each object allocation but still no changes.

Thank you!

È stato utile?

Soluzione

With no code provided here is the best course of action

  1. Use ARC
  2. Fix all compiler warnings
  3. Run Analyzer in Xcode and fix any warnings.
  4. Use Generation Analysis (Heapshot) in Instruments

Use instruments to check for leaks and memory loss due to retained but not leaked memory. The latter is unused memory that is still pointed to. Use Heapshot in the Allocations instrument on Instruments.

For HowTo use Heapshot to find memory creap, see: bbum blog

Basically there method is to run Instruments allocate tool, take a heapshot, run an intuition of your code and another heapshot repeating 3 or 4 times. This will indicate memory that is allocated and not released during the iterations.

To figure out the results disclose to see the individual allocations.

If you need to see where retains, releases and autoreleases occur for an object use instruments:

Run in instruments, in Allocations set "Record reference counts" on on (you have to stop recording to set the option). Cause the picker to run, stop recording, search for there ivar (datePickerView), drill down and you will be able to see where all retains, releases and autoreleases occurred.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top