0

I have an object that contains a array. On initialization of this object, the array is allocated and properly filled (as I can see in the debugger). This object is use to manage elements in a single view.

My problem is that when I try to call the object a second time, the array (and all other parameter of this object) are nil yet they have a memory address (again as seen in debugger).

This is the .h of the object in question :

#import <Foundation/Foundation.h>

#import "ObjectDef.h"
#import "AbstractNode.h"

@interface RenderingMachine : NSObject
{    
    NSMutableArray* _objectID;    // pair list
    NSMutableArray* _objectList;  // node list
    ObjectDef* _defs;             // definition of pairs

    unsigned int _size;
    unsigned int _edgeSize;

    AbstractNode* _lastNode;
}

-(void) InitializeMachine;
-(bool) AddObjectByIndex:(int)index :(float)x :(float)y :(float)originX :(float)originY;
-(bool) AddObjectByType:(NSString*)type;
-(NSMutableArray*) GetObjectID;
-(NSMutableArray*) GetObjectList;
-(unsigned int) Size;
-(void) DrawAllNode;
-(int) ComputePar;
-(void) ComputeLastEdge:(int)edgeCount;

//+(RenderingMachine*) GetMachine;

@end

My main problem right now is with _defs which is filled in InitDefinitions :

-(void) InitializeMachine
{
    _defs = [[ObjectDef alloc] init];
    [_defs InitDefinitions];
    _objectID = [[NSMutableArray alloc] init];
    _objectList = [[NSMutableArray alloc] init];
    _objectID = [NSMutableArray arrayWithObject:[_defs GetPair:3]]; // adding the field node ID

    AbstractNode* rootNode = [[FieldNode alloc] init];
    _objectList = [NSMutableArray arrayWithObject:rootNode]; // adding the field node as root node

    _size = 1;
    _edgeSize = 0;
}

What I'd like to know is if might be a bad alloc / init call or could it be a problem with the ARC of xcode because this particular file compiles with ARC (the other being ignore with "-fno-objc-arc").

Also, as mentionned the _defs is problematic, but all the property declared under @interface are having the same problem.

2
  • You need to include more code. ObjectDef's init method and InitDefinitions for starters, and whatever code you create RenderingMachine in and call InitializeMachine from. Also, please follow objective-c conventions with method, ivar and class naming - only classes start with upper case letters. It's amazing how much harder it makes it to read if you capitalise your method names! Commented Mar 22, 2012 at 7:35
  • Also you don't need to initialize mutable array twice, try with arrayWithCapacity and then addObject: or just arrayWithObject: alone. Then, as suggested, try to post more code. Commented Mar 22, 2012 at 8:41

1 Answer 1

2

First you create a retained object with _objectID = [[NSMutableArray alloc] init];
and then you overwrite it with an autoreleased one _objectID = [NSMutableArray arrayWithObject:[_defs GetPair:3]];

to add the object better use [_objectID addObject:[_defs GetPair:3]];

same thing with the _objectList Object

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.