You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Andrew Grieve (JIRA)" <ji...@apache.org> on 2013/02/07 16:25:13 UTC
[jira] [Resolved] (CB-2395) iOS: Timing issue in user-agent lock
mechanism (memory leaking)
[ https://issues.apache.org/jira/browse/CB-2395?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andrew Grieve resolved CB-2395.
-------------------------------
Resolution: Fixed
Fix Version/s: 2.5.0
Assignee: Andrew Grieve (was: Shazron Abdullah)
Christoph, thanks for the detailed explanation! I agree with your finding and have submitted a fix!
https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;a=commit;h=9e39f7ef8096fb15b38121ab0e245a3a958d9cbb
It unfortunately won't make it in for our 2.4 release.
> iOS: Timing issue in user-agent lock mechanism (memory leaking)
> ---------------------------------------------------------------
>
> Key: CB-2395
> URL: https://issues.apache.org/jira/browse/CB-2395
> Project: Apache Cordova
> Issue Type: Bug
> Components: iOS
> Affects Versions: 2.4.0
> Reporter: Christoph Jerolimov
> Assignee: Andrew Grieve
> Fix For: 2.5.0
>
>
> I found a obj-c reference counting problem with Cordova 2.4.
> Analysing the retain/release calls of CDVViewController i found the following problem. If you just want fix this i added a recommendation at the! ;-)
>
> *Retain:* When the view was displayed they load the request in a c-block (simplified source here!). This callback-code needs the CDVViewController itself:
> {code}
> - (void)viewDidLoad {
> ...
> [CDVUserAgentUtil acquireLock:^(NSInteger lockToken) {
> _userAgentLockToken = lockToken;
> [CDVUserAgentUtil setUserAgent:self.userAgent lockToken:lockToken];
> NSURLRequest* appReq = [NSURLRequest requestWithURL:appURL ....;
> [self.webView loadRequest:appReq];
> }];
> }
> {code}
> *Release:* To release the block (and so the CDVViewController) it's required to call the the {{acquireLock}} associated {{releaseLock}} method. This was called in the delegate methods of the webview.
> {code}
> - (void)webViewDidFinishLoad:(UIWebView*)theWebView AND
> - (void)webView:(UIWebView*)webView didFailLoadWithError:(NSError*)error
> ...
> if (_userAgentLockToken != 0) {
> [CDVUserAgentUtil releaseLock:_userAgentLockToken];
> _userAgentLockToken = 0;
> }
> {code}
> *But:* If the webview.delegate was set to nil before the response was received the {{releaseLock}} was never called!
> *To fix this* please add these lines at least two the {{dealloc}} method!
> For iOS 5.x it makes also sense to add this to the {{viewDidUnload}} method where the webView.delegate was also removed. Otherwise remove this deprecated method completly. Feel also free to externalize the then 3 or 4 calls to CDVUserAgentUtil to a small privat method.
> {code}
> if (_userAgentLockToken != 0) {
> [CDVUserAgentUtil releaseLock:_userAgentLockToken];
> _userAgentLockToken = 0;
> }
> {code}
> Thank you and best regards,
> Christoph
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira