{"action":"created","issue":{"url":"https://api.github.com/repos/QuickBlox/quickblox-ios-sdk/issues/387","repository_url":"https://api.github.com/repos/QuickBlox/quickblox-ios-sdk","labels_url":"https://api.github.com/repos/QuickBlox/quickblox-ios-sdk/issues/387/labels{/name}","comments_url":"https://api.github.com/repos/QuickBlox/quickblox-ios-sdk/issues/387/comments","events_url":"https://api.github.com/repos/QuickBlox/quickblox-ios-sdk/issues/387/events","html_url":"https://github.com/QuickBlox/quickblox-ios-sdk/issues/387","id":147254511,"number":387,"title":"TUploadfile is causing a memory leak?","user":{"login":"cvezina","id":2745102,"avatar_url":"https://avatars.githubusercontent.com/u/2745102?v=3","gravatar_id":"","url":"https://api.github.com/users/cvezina","html_url":"https://github.com/cvezina","followers_url":"https://api.github.com/users/cvezina/followers","following_url":"https://api.github.com/users/cvezina/following{/other_user}","gists_url":"https://api.github.com/users/cvezina/gists{/gist_id}","starred_url":"https://api.github.com/users/cvezina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cvezina/subscriptions","organizations_url":"https://api.github.com/users/cvezina/orgs","repos_url":"https://api.github.com/users/cvezina/repos","events_url":"https://api.github.com/users/cvezina/events{/privacy}","received_events_url":"https://api.github.com/users/cvezina/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"Raikerian","id":8850270,"avatar_url":"https://avatars.githubusercontent.com/u/8850270?v=3","gravatar_id":"","url":"https://api.github.com/users/Raikerian","html_url":"https://github.com/Raikerian","followers_url":"https://api.github.com/users/Raikerian/followers","following_url":"https://api.github.com/users/Raikerian/following{/other_user}","gists_url":"https://api.github.com/users/Raikerian/gists{/gist_id}","starred_url":"https://api.github.com/users/Raikerian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Raikerian/subscriptions","organizations_url":"https://api.github.com/users/Raikerian/orgs","repos_url":"https://api.github.com/users/Raikerian/repos","events_url":"https://api.github.com/users/Raikerian/events{/privacy}","received_events_url":"https://api.github.com/users/Raikerian/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2016-04-10T19:15:33Z","updated_at":"2016-04-11T14:42:21Z","closed_at":null,"body":"Doing a simple call to TUploadFile is causing a memory leak. Basically, if I am in a QBChatDialog and the user send a message that is an image (via TUploadFile), then after the user leave the chat dialog, dealloc of the object encapsulating the QBChatDialog is not called. If no image are sent (just text messages), everything is working as expected and when the user leave the dialog, dealloc is called as expected. \r\n\r\nHere is the sample code used:\r\n\r\n```objectivec\r\n- (void) sendImage: (UIImage*) image\r\n{\r\n\tNSData *imageData = UIImageJPEGRepresentation (image, 0.3);\r\n\t\r\n\t[self startLoading];\r\n\r\n\t// TODO: TUploadFile is causing a leak\r\n\t\r\n\t[QBRequest TUploadFile:imageData fileName:@\"image.jpeg\" contentType:@\"image/jpg\" isPublic: NO successBlock:^(QBResponse *response, QBCBlob *uploadedBlob) {\r\n\t} statusBlock:^(QBRequest *request, QBRequestStatus *status) {\r\n\t\t[self stopLoading];\r\n\t} errorBlock:^(QBResponse *response) {\r\n\t\t[self stopLoading];\r\n\t\t[[TWMessageBarManager sharedInstance] showMessageWithTitle: @\"Something went wrong!\" description: nil type: TWMessageBarMessageTypeError];\r\n\t\tNSLog(@\"GalPal - (Error) : Error while sending image: %@\", response.error.description);\r\n\t}];\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/QuickBlox/quickblox-ios-sdk/issues/comments/208380006","html_url":"https://github.com/QuickBlox/quickblox-ios-sdk/issues/387#issuecomment-208380006","issue_url":"https://api.github.com/repos/QuickBlox/quickblox-ios-sdk/issues/387","id":208380006,"user":{"login":"Raikerian","id":8850270,"avatar_url":"https://avatars.githubusercontent.com/u/8850270?v=3","gravatar_id":"","url":"https://api.github.com/users/Raikerian","html_url":"https://github.com/Raikerian","followers_url":"https://api.github.com/users/Raikerian/followers","following_url":"https://api.github.com/users/Raikerian/following{/other_user}","gists_url":"https://api.github.com/users/Raikerian/gists{/gist_id}","starred_url":"https://api.github.com/users/Raikerian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Raikerian/subscriptions","organizations_url":"https://api.github.com/users/Raikerian/orgs","repos_url":"https://api.github.com/users/Raikerian/repos","events_url":"https://api.github.com/users/Raikerian/events{/privacy}","received_events_url":"https://api.github.com/users/Raikerian/received_events","type":"User","site_admin":false},"created_at":"2016-04-11T14:42:20Z","updated_at":"2016-04-11T14:42:20Z","body":"Hi @cvezina \r\n\r\nThank you for reporting the issue. I was able to catch and fix it. It will be available in the next release.\r\nFor now there is a possible solution for you to make a weak reference for self, in order for block not to retain it. Here is an example:\r\n\r\n```objectivec\r\n- (void) sendImage: (UIImage*) image\r\n{\r\n    NSData *imageData = UIImageJPEGRepresentation (image, 0.3);\r\n    \r\n    [self startLoading];\r\n    \r\n    // TODO: TUploadFile is causing a leak\r\n    \r\n    __weak __typeof(self)weakSelf = self;\r\n    [QBRequest TUploadFile:imageData fileName:@\"image.jpeg\" contentType:@\"image/jpg\" isPublic: NO successBlock:nil\r\n               statusBlock:^(QBRequest *request, QBRequestStatus *status) {\r\n                   \r\n        [weakSelf stopLoading];\r\n        \r\n    } errorBlock:^(QBResponse *response) {\r\n        \r\n        [weakSelf stopLoading];\r\n        [[TWMessageBarManager sharedInstance] showMessageWithTitle: @\"Something went wrong!\" description: nil type: TWMessageBarMessageTypeError];\r\n        NSLog(@\"GalPal - (Error) : Error while sending image: %@\", response.error.description);\r\n    }];\r\n}\r\n```\r\n"}}