Hi all..
In my iPhone app,
i make use of a static object...
The getter and setter method for the static object is as follows...
Hope the above code is OK....
In one of my viewController i am doing an assignment like
I know its a "copy by reference"...
But i want the "localCartObjectInFirstViewController" to have a separate memory containing the return value of [cart getMyCart];
If i allocate memory for localCartObjectInFirstViewController and do the above will result in a memory leak , right???
So whats the solution???
In my iPhone app,
i make use of a static object...
The getter and setter method for the static object is as follows...
Code:
+(cart *)getMyCart
{
if(staticCartObject == nil)
{
staticCartObject = [[cart alloc]init];
staticCartObject.productArray = [[NSMutableArray alloc]init];
}
return cartObject;
}
+(void)setCart:(cart*)newCart
{
[staticCartObject release];
[newCart retain];
staticCartObject=newCart;
}
Hope the above code is OK....
In one of my viewController i am doing an assignment like
Code:
localCartObjectInFirstViewController = [cart getCartObject];
I know its a "copy by reference"...
But i want the "localCartObjectInFirstViewController" to have a separate memory containing the return value of [cart getMyCart];
If i allocate memory for localCartObjectInFirstViewController and do the above will result in a memory leak , right???
So whats the solution???