I am curious, if you call a method which returns an object, but you dont store it anywhere, does it still exist on the stack forever, creating a memory leak?
Ex.
- (NSString *)getString; //method prototype
[myObject getString];
NSString *x = nil;
x = [MyObject getString];
NSLog(x);
x = [MyObject getString];
NSLog(x);
x = [MyObject getString];
I guess what I am asking is, is the memory required for the pointer (4/8 bytes) leaked when it gets pushed on the stack, and nothing pops it?
[self method];
int getInt(void);
int main(int argc, char *argv[]) {
getInt();
}
int getInt(){
return 5;
}
.file "testret.c"
.text
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $4, %esp
call getInt
addl $4, %esp
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.size main, .-main
.globl getInt
.type getInt, @function
getInt:
pushl %ebp
movl %esp, %ebp
movl $5, %eax
popl %ebp
ret
.size getInt, .-getInt
NSString *myString = @"My string";
[myString copy];
[myString copy];
[myString copy];
- (NSString *)foo(){
NSString *str = [[NSString alloc]initWithString:@"hello world!"];
return [str autorelease];
}