Hi All,
My environment is Snow leopard 10.6.6 I am using Xcode for developing an application. I am relatively new to Cocoa programming.
Wanted to know if it is correct to release an memory of an object immediately after the object has been set within an dictionary.
I have provided the code snipped to illustrate the same.
NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithDictionary:dictionary1];//dictionary1 is some source dictionary.
NSButton *button = [[NSButton alloc]initWithFrame:currentRect];//rect of some size .
[tempDic setObject:button forKey:BUTTON_OBJ];
[button release];//Can I call release here after assigning to Dictionary.
Here after setting the button object to tempDic, I am releasing the object's memory. I plan to use the button object somewhere else. This code works as expected (i mean else where I am able to access the button object form the dictionary and it is valid).
Is what i am doing right or should I not release the button object as the same reference is being set to the dictionary also?
My environment is Snow leopard 10.6.6 I am using Xcode for developing an application. I am relatively new to Cocoa programming.
Wanted to know if it is correct to release an memory of an object immediately after the object has been set within an dictionary.
I have provided the code snipped to illustrate the same.
NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithDictionary:dictionary1];//dictionary1 is some source dictionary.
NSButton *button = [[NSButton alloc]initWithFrame:currentRect];//rect of some size .
[tempDic setObject:button forKey:BUTTON_OBJ];
[button release];//Can I call release here after assigning to Dictionary.
Here after setting the button object to tempDic, I am releasing the object's memory. I plan to use the button object somewhere else. This code works as expected (i mean else where I am able to access the button object form the dictionary and it is valid).
Is what i am doing right or should I not release the button object as the same reference is being set to the dictionary also?