Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

malloc: *** error for object 0x165060: pointer being freed was not allocated?

Tags:

ios

iphone

ipad

I have an application in which i have some videos and audios and some inapp purchases.all r great in simulator and working perfectly.But yesterday i have created an application and trying to run on it its crashing from the begning.The error report is

malloc: *** error for object 0x165060: pointer being freed was not allocated
  *** set a breakpoint in malloc_error_break to debug

can anybody knows the solution .i dont know where it is going wrong and in simulator it is working perfectly.can anybody help me?

like image 609
hacker Avatar asked Aug 21 '12 05:08

hacker


3 Answers

I followed as talkol suggested

In my case I replaced following line

[myMutualArray removeAllObjects];

with

[myMutualArray removeAllObjects]; myMutualArray = nil;

And the error gone!

like image 107
Avin Avatar answered Nov 14 '22 16:11

Avin


You are probably releasing an object too many times (for example, calling alloc once and release twice). To find out where, take a look at the techniques in this question: How to find the cause of a malloc "double free" error?

I personally like the NSZombieEnabled method.

Another tip, is to set your variables to nil after you release them.

For example: [bla release]; bla = nil;

This makes sure you will not accidentally release them twice since releasing nil does nothing.

like image 38
talkol Avatar answered Nov 14 '22 14:11

talkol


Please test the program for memory leaks,also check autoreleases and whether you are releasing objects properly or not.Also we need to check whether a released object has a memory allocated or not.You also need to be careful regarding autorelease,because accidentally we might release an array or a string or any object that is already autoreleased...

Here are some of the tips to trace out the exact problem:

  1. You can test for leaks by analyzing your project(click shift+command+k)

  2. Use instruments tool i.e. running for leaks

  3. Enable NSZombie in Xcode,procedure can be found here

Hope it helps and works!

like image 1
Eshwar Chaitanya Avatar answered Nov 14 '22 14:11

Eshwar Chaitanya