I want to make a copy of a GKSession object and I implement copyWithZone as follow :
-(id)copyWithZone:(NSZone *)zone {
GKSession *kati = [[GKSession allocWithZone: zone] init];
kati=_currentSession;
return kati;}
Nevertheless I don't take a copy of the initial object but a reference to that.
Am I missing something...;
The implementation of the copyWithZone is the way to make a copy of a GKSession object, or not?
Thanks in advance...!
Let's take a look at what your code is doing:
You allocate a new
GKSession
object, and update thekati
variable to point to the object.You change the
kati
variable to point to another object. This means the object you just allocated is leaked; you don't have a pointer to it anymore, but it wasn't ever deallocated.You return the value of the
kati
variable, which is a pointer to the_currentSession
object.This is clearly not what you want. You want to create a new
GKSession
with the same underlying information as_currentSession
, right? In that case, I would start with: