Reputation: 1
I am having a function that is being called many times , it creates data to send to server via tcp. i think i am loosing the data somewhere .
I am wondering what is the right way to go :
using finalData=[[NSMutableData alloc]init];
at the start of the program,and than the function to send is like (being call many times) :
-(NSMutableData*)setProtocolDataForString:(NSString*)data{
finalData=nil;
//here construct new finalData..
or, whitin the function , retain it :
-(NSMutableData*)setProtocolDataForString:(NSString*)data{
finalData=[[NSMutableData data]retain]; //but its wrong because it happens many times
//construct a finalData to send
I am not using ARC . First way crash, second way-i think i am loosing him ..
Should i use property? if yes, what is the exact way to do so ?
Upvotes: 0
Views: 87
Reputation: 25907
Ok, you are sending a chunk of data everytime you call
-(NSMutableData*)setProtocolDataForString:(NSString*)data;
You could do something like:
if(finalData){
[finalData release];
finalData = nil;
}
finalData = [[NSMutableArray alloc] init];
Upvotes: 1