[
https://issues.apache.org/jira/browse/CB-2395?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13573460#comment-13573460
]
Christoph Jerolimov commented on CB-2395:
-----------------------------------------
It would also be nice to split the {{viewDidLoad}} which contains over 150+
line into several small method. Currently it's not possible to override such
parts (for example to fix this with a workaround).
> 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: Shazron Abdullah
>
> 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