Page 1 of 2
memory leak
Posted: 15 Mar 2012, 11:43
by maomao
hi
i found all the object created by the sfs framework can't be released ,i hope you can help me to solve this problem quickly, our project is really in a hurry
Re: memory leak
Posted: 15 Mar 2012, 12:21
by itsmylifesoham
hi,
could you explain a bit more about what objects are you creating and if this problem is on client side or serverside?
which client api are you using as3/unity ?
generally it shouldnt be related to sfs as sfs is just an api.
if you could post a small fragment of your code where an object is not being able to release i could help.
Re: memory leak
Posted: 15 Mar 2012, 14:45
by maomao
thanks for help me
i'm using the iOS api ,and the image is taked from instruments
Re: memory leak
Posted: 15 Mar 2012, 14:47
by maomao
Code: Select all
- (void)viewDidLoad{
sfs = [[SmartFox2XClient alloc] initSmartFoxWithDebugMode:NO delegate:self];
[sfs connect:@"www.h-tlk.mobi" port:9933];
[super viewDidLoad];
}
-(void)onConnection:(SFSEvent *)evt{
SFSObject *object = [SFSObject newInstance];
[object putUtfString:@"login_type" value:@"1"];
LoginRequest *request = [[LoginRequest alloc] initWithUserName:@"admin" password:@"123455" zoneName:@"JKSJ" params:object];
[sfs send:request];
}
-(void)onLogin:(SFSEvent *)evt{
[sfs send:[JoinRoomRequest requestWithId:@"minihome"]];
}
-(void)onRoomJoin:(SFSEvent *)evt{
room = [evt.params objectForKey:@"room"];
[self startTest];
}
-(void)startTest{
[NSTimer scheduledTimerWithTimeInterval:.3f target:self selector:@selector(sendMsg:) userInfo:nil repeats:YES];
}
-(void)sendMsg:(id)sender{
SFSObject *object = [SFSObject newInstance];
[object putInt:@"server_code" value:9022];
ExtensionRequest *request = [ExtensionRequest requestWithExtCmd:@"sms_sys_initialization" params:object room:room];
[sfs send:request];
}
-(void)onExtensionResponse:(SFSEvent *)event{
SFSObject *object = [event.params objectForKey:@"params"];
NSString *code = [NSString stringWithFormat:@"%d",[object getInt:@"server_code"]];
NSString *str = [object getUtfString:@"server_parame"];
NSLog(@"%d:%@",code,str);
}
-(void)onRoomJoinError:(SFSEvent *)evt{
NSLog(@"rom join error");
}
-(void)onLoginError:(SFSEvent *)evt{
NSLog(@"login error");
}
Re: memory leak
Posted: 15 Mar 2012, 14:51
by maomao
i don't know if there is something wrong with my code ,but last version is all right for me ,just with the same code!
Re: memory leak
Posted: 15 Mar 2012, 15:29
by itsmylifesoham
oops, m so sorry, i havnt worked with ios client...
Re: memory leak
Posted: 15 Mar 2012, 15:48
by maomao
it doesn't matter ,thanks for your reply
Re: memory leak
Posted: 15 Mar 2012, 17:47
by A51Integrated
This is noted in the release notes of the new API. SFSObject previously was created using autorelease in the API. That has since been removed to prevent XCode from throwing warnings.
The proper way to instantiate an SFSObject is
Code: Select all
SFSObject *obj = [[SFSObject newInstance] autorelease];
This change was implemented in SFS2XAPI v1.0.0
Re: memory leak
Posted: 16 Mar 2012, 04:34
by maomao
hi
i've updated to the latest api and release sfsobject myself,but there isn't anything different
Code: Select all
- (void)viewDidLoad{
sfs = [[SmartFox2XClient alloc] initSmartFoxWithDebugMode:NO delegate:self];
[sfs connect:@"192.168.16.109" port:9933];
[super viewDidLoad];
}
-(void)onConnection:(SFSEvent *)evt{
SFSObject *object = [SFSObject newInstance];
[object putUtfString:@"login_type" value:@"1"];
LoginRequest *request = [[LoginRequest alloc] initWithUserName:@"admin" password:@"123455" zoneName:@"JKSJ" params:object];
[sfs send:request];
[object release];
[request release];
}
-(void)onLogin:(SFSEvent *)evt{
[sfs send:[JoinRoomRequest requestWithId:@"minihome"]];
}
-(void)onRoomJoin:(SFSEvent *)evt{
room = [evt.params objectForKey:@"room"];
[self startTest];
}
-(void)startTest{
[NSTimer scheduledTimerWithTimeInterval:.3f target:self selector:@selector(sendMsg:) userInfo:nil repeats:YES];
}
-(void)sendMsg:(id)sender{
SFSObject *object = [SFSObject newInstance];
[object putInt:@"server_code" value:9022];
ExtensionRequest *request = [ExtensionRequest requestWithExtCmd:@"sms_sys_initialization" params:object room:room];
[sfs send:request];
[object release];
}
-(void)onExtensionResponse:(SFSEvent *)event{
SFSObject *object = [event.params objectForKey:@"params"];
NSString *code = [NSString stringWithFormat:@"%d",[object getInt:@"server_code"]];
NSString *str = [object getUtfString:@"server_parame"];
NSLog(@"%@:%@",code,str);
}
Re: memory leak
Posted: 16 Mar 2012, 10:38
by A51Integrated
Don't release them, autorelease them as in my previous example. You may will run into issues if you release them right after instantiation.
Re: memory leak
Posted: 16 Mar 2012, 14:39
by maomao
i use your code but it doesn't work
Code: Select all
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad{
sfs = [[SmartFox2XClient alloc] initSmartFoxWithDebugMode:NO delegate:self];
[sfs connect:@"192.168.16.109" port:9933];
[super viewDidLoad];
}
-(void)onConnection:(SFSEvent *)evt{
SFSObject *object = [[SFSObject newInstance] autorelease];
[object putUtfString:@"login_type" value:@"1"];
LoginRequest *request = [[LoginRequest alloc] initWithUserName:@"admin" password:@"123455" zoneName:@"JKSJ" params:object];
[sfs send:request];
[request release];
}
-(void)onLogin:(SFSEvent *)evt{
[sfs send:[JoinRoomRequest requestWithId:@"minihome"]];
}
-(void)onRoomJoin:(SFSEvent *)evt{
room = [evt.params objectForKey:@"room"];
[self startTest];
}
-(void)startTest{
[NSTimer scheduledTimerWithTimeInterval:.3f target:self selector:@selector(sendMsg:) userInfo:nil repeats:YES];
}
-(void)sendMsg:(id)sender{
SFSObject *object = [[SFSObject newInstance] autorelease];
[object putInt:@"server_code" value:9022];
ExtensionRequest *request = [ExtensionRequest requestWithExtCmd:@"sms_sys_initialization" params:object room:room];
[sfs send:request];
}
-(void)onExtensionResponse:(SFSEvent *)event{
SFSObject *object = [event.params objectForKey:@"params"];
NSString *code = [NSString stringWithFormat:@"%d",[object getInt:@"server_code"]];
NSString *str = [object getUtfString:@"server_parame"];
}
-(void)onRoomJoinError:(SFSEvent *)evt{
NSLog(@"rom join error");
}
-(void)onLoginError:(SFSEvent *)evt{
NSLog(@"login error");
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
Re: memory leak
Posted: 16 Mar 2012, 14:54
by A51Integrated
What doesn't work? With autorelease, the objects will be cleared when memory is required - not instantly.
Re: memory leak
Posted: 16 Mar 2012, 15:09
by maomao
you can see the image i uploaded before! all the sfsobject、datawrapper can't be released
Re: memory leak
Posted: 16 Mar 2012, 16:17
by A51Integrated
OK. There may be an issues with garbage collection in the framework. We'll have closer look.
Re: memory leak
Posted: 21 Mar 2012, 09:42
by maomao
hi
do you have any solution for the issue,we are really in a hurry