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

后端 未结 6 969
温柔的废话
温柔的废话 2020-12-31 10:18

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 applicat

相关标签:
6条回答
  • 2020-12-31 10:54

    I followed as talkol suggested

    In my case I replaced following line

    [myMutualArray removeAllObjects];

    with

    [myMutualArray removeAllObjects]; myMutualArray = nil;
    

    And the error gone!

    0 讨论(0)
  • 2020-12-31 10:54

    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!

    0 讨论(0)
  • 2020-12-31 11:04

    Without seeing any code we can't help you with this. But you can find the problem yourself, the error message even tells you what to do: set a breakpoint on malloc_error_break and you usually will find the code that caused the problem in the stack trace.

    Just because it works in the simulator just doesn't mean that your code is 100% correct. some bugs only show up on a real device (or vice versa).

    0 讨论(0)
  • 2020-12-31 11:08

    This may caused by safari inspector, you can disable them. Refer to this post for more details.

    0 讨论(0)
  • 2020-12-31 11:09

    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.

    0 讨论(0)
  • 2020-12-31 11:10

    I got this kind of error when your trying to call free on a pointer that the address is not at start of block. For example:

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 int main()
     5 {
     6 
     7    int a; // some integers
     8    int *pi;     // a pointer to an integer
     9    pi =(int*) malloc( 1*sizeof(int) );
    10 
    11    a = 5;
    12    pi = &a; // pi points to a
    13    pi++; // pi is not anymore at start
    14    free(pi);
    15 
    16    printf("at the end, we are alived \n"); // this will not be printed
    17  
    18    return 0;
    19 }
    
    0 讨论(0)
提交回复
热议问题