memory leak

Post here your questions about the Objective-C API for SFS2X

Moderators: Bax, Lapo, A51Integrated

memory leak

Postby maomao » 15 Mar 2012, 11:43

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
maomao
 
Posts: 18
Joined: 08 Nov 2011, 04:48

Re: memory leak

Postby itsmylifesoham » 15 Mar 2012, 12:21

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.
itsmylifesoham
 
Posts: 186
Joined: 16 Oct 2011, 14:33

Re: memory leak

Postby maomao » 15 Mar 2012, 14:45

thanks for help me
i'm using the iOS api ,and the image is taked from instruments
Attachments
leak.jpg
(116.37 KiB) Not downloaded yet
Last edited by maomao on 15 Mar 2012, 15:21, edited 2 times in total.
maomao
 
Posts: 18
Joined: 08 Nov 2011, 04:48

Re: memory leak

Postby maomao » 15 Mar 2012, 14:47

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");
}
Last edited by maomao on 15 Mar 2012, 15:32, edited 1 time in total.
maomao
 
Posts: 18
Joined: 08 Nov 2011, 04:48

Re: memory leak

Postby maomao » 15 Mar 2012, 14:51

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!
maomao
 
Posts: 18
Joined: 08 Nov 2011, 04:48

Re: memory leak

Postby itsmylifesoham » 15 Mar 2012, 15:29

oops, m so sorry, i havnt worked with ios client... :|
itsmylifesoham
 
Posts: 186
Joined: 16 Oct 2011, 14:33

Re: memory leak

Postby maomao » 15 Mar 2012, 15:48

:D it doesn't matter ,thanks for your reply
maomao
 
Posts: 18
Joined: 08 Nov 2011, 04:48

Re: memory leak

Postby A51Integrated » 15 Mar 2012, 17:47

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
A51 Integrated
http://a51integrated.com / +1 416-703-2300
User avatar
A51Integrated
 
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada

Re: memory leak

Postby maomao » 16 Mar 2012, 04:34

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);
}
Attachments
leak.jpg
(116.37 KiB) Not downloaded yet
maomao
 
Posts: 18
Joined: 08 Nov 2011, 04:48

Re: memory leak

Postby A51Integrated » 16 Mar 2012, 10:38

Don't release them, autorelease them as in my previous example. You may will run into issues if you release them right after instantiation.
A51 Integrated
http://a51integrated.com / +1 416-703-2300
User avatar
A51Integrated
 
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada

Re: memory leak

Postby maomao » 16 Mar 2012, 14:39

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
maomao
 
Posts: 18
Joined: 08 Nov 2011, 04:48

Re: memory leak

Postby A51Integrated » 16 Mar 2012, 14:54

What doesn't work? With autorelease, the objects will be cleared when memory is required - not instantly.
A51 Integrated
http://a51integrated.com / +1 416-703-2300
User avatar
A51Integrated
 
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada

Re: memory leak

Postby maomao » 16 Mar 2012, 15:09

you can see the image i uploaded before! all the sfsobject、datawrapper can't be released
maomao
 
Posts: 18
Joined: 08 Nov 2011, 04:48

Re: memory leak

Postby A51Integrated » 16 Mar 2012, 16:17

OK. There may be an issues with garbage collection in the framework. We'll have closer look.
A51 Integrated
http://a51integrated.com / +1 416-703-2300
User avatar
A51Integrated
 
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada

Re: memory leak

Postby maomao » 21 Mar 2012, 09:42

hi
do you have any solution for the issue,we are really in a hurry
maomao
 
Posts: 18
Joined: 08 Nov 2011, 04:48

Next

Return to SFS2X iPhone / iPad / OSX API

Who is online

Users browsing this forum: No registered users and 4 guests