Auto-repeat Objc memory break

I hunted all over my code and cannot find the source of this failure: I try to decode an object using NSKeyedUnarchiver, and it falls on it every time and says:

*** __NSAutoreleaseFreedObject(): release of previously deallocated object (0x1008ad200) ignored
*** __NSAutoreleaseFreedObject(): release of previously deallocated object (0x1008ab200) ignored
*** __NSAutoreleaseFreedObject(): release of previously deallocated object (0x1008a8c00) ignored

A good reason why initWithCoder was not called was a problem with [super initWithCoder:]; It still drives me crazy. I looked, and pointers and NSData objects are what goes wrong:

    vertices = malloc(size_point3D * vertexCount);
    textureCoords = malloc(size_point2D * textureCount);
    normals = malloc(size_point3D * normalCount);
    faces = malloc(sizeof(GLuint) * faceCount);


    NSData *vertexData = [[NSData alloc] initWithData:[coder decodeObjectForKey:@"vertices"]];
    NSData *textureData = [[NSData alloc] initWithData:[coder decodeObjectForKey:@"textureCoords"]];
    NSData *normalData = [[NSData alloc] initWithData:[coder decodeObjectForKey:@"normals"]];
    NSData *faceData = [[NSData alloc] initWithData:[coder decodeObjectForKey:@"faces"]];


    memcpy(vertices, [vertexData bytes],  sizeof(point3D) * vertexCount);
    memcpy(textureCoords, [textureData bytes], sizeof(point2D) * textureCount);
    memcpy(normals, [normalData bytes], sizeof(point3D) * normalCount);
    memcpy(faces, [faceData bytes], sizeof(GLuint) * faceCount);

    [vertexData release];
    [textureData release];
    [normalData release];
    [faceData release];

I tried to save everything in this part (even a string), but that does not help.

+3
source share
4 answers

This was difficult to solve in part because debugging memory behaves inconsistently.

2 JGStaticModel JGModel. - unarchiver , initWithCoder JGModel, JGStaticModel. , . , , . , , , JGStaticModel, JGModel, , .

!

+2
+1

(Run → Run with Performance tools) NSZombiesEnabled , - (id) - (void) , . / . , . , , , , /

0

.

:

"NSAutoreleaseHaltOnFreedObject" ​​ "YES",

0

Source: https://habr.com/ru/post/1763387/


All Articles