iconara
Registered
<tt>
NSString *str;
str = [[NSString alloc] initWithString
"string"];
str = [[NSString alloc] initWithString
"string again"];
[str release];
</tt>
Does this create a memory leak? Should the variable <tt>str</tt> have been released beetween the allocations? I Think it should, but I don't think that it is obvious. Think about the same code in Java:
<tt>
String str;
str = new String( "string" );
str = new String( "string again" );
// the object moves out of scope and is freed by the GC
</tt>
in this code, when is the object containing "string" freed? Could it be that in Java, the memory holding the object is overwritten and in Cocoa/ObjC a new a new chunk of memy is used for the new object since we call +alloc. I don't think that I have understood all of the implications...
theo
NSString *str;
str = [[NSString alloc] initWithString

str = [[NSString alloc] initWithString

[str release];
</tt>
Does this create a memory leak? Should the variable <tt>str</tt> have been released beetween the allocations? I Think it should, but I don't think that it is obvious. Think about the same code in Java:
<tt>
String str;
str = new String( "string" );
str = new String( "string again" );
// the object moves out of scope and is freed by the GC
</tt>
in this code, when is the object containing "string" freed? Could it be that in Java, the memory holding the object is overwritten and in Cocoa/ObjC a new a new chunk of memy is used for the new object since we call +alloc. I don't think that I have understood all of the implications...
theo