Skip to content

Instantly share code, notes, and snippets.

@patelrohan
Created February 27, 2012 06:51
Show Gist options
  • Save patelrohan/1922022 to your computer and use it in GitHub Desktop.
Save patelrohan/1922022 to your computer and use it in GitHub Desktop.
Memory Leaks and Bad memory usage
//===================== Memory Leak===========================
NSString *str =[[NSString alloc]initwithFormate:@"Hello"];
UILabel *lbl=[[UILabel alloc]init];
lbl.text= str;
[str release];
UILabel *lbl2=[[UILabel alloc]init];
lbl2.text=str; // Gives memory leak as str is released
//=====================Bad memory usage===========================
NSString *str =[[NSString alloc]initwithFormate:@"Hello"];
UILabel *lbl;
lbl.text= str;
// bad memory usage as allocated string object is not released.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment