Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

IOS memory leak because of WWW object

$
0
0
Hi there, I have a nifty memory leak when I run my project on the IOS platform. I have checked it using instruments leak tool and debug using Xcode 6. In some cases it looks like the WWW object is never disposed. ------------------------------------------------------------------- I°) Here is the part of code that handle sending WWW requests: private void issueRequestWithoutQueuing(string url, Dictionary parameters = null, Callback successCallback = null, Callback apiFailureCallback = null, Callback layerFailureCallback = null, bool showSpinner = false) { QueuedWWWObject queueWWW = new QueuedWWWObject(); queueWWW.url = url; queueWWW.successCB = successCallback; queueWWW.apiFailureCB = apiFailureCallback; queueWWW.layerFailureCB = layerFailureCallback; if (parameters != null) { queueWWW.parameters = parameters; } issueRequest(queueWWW, showSpinner); } private void issueRequest(QueuedWWWObject queueWWW, bool showSpinner = false) { numberRequestInProgress ++; WWW www; if (queueWWW.parameters != null && queueWWW.parameters.Count != 0) { WWWForm form = new WWWForm(); foreach (KeyValuePair pair in queueWWW.parameters) { form.AddField(pair.Key, pair.Value); } www = new WWW(queueWWW.url, form); } else { www = new WWW(queueWWW.url); } NetworkManager.instance.StartCoroutine(WaitForRequest(www, queueWWW, queueWWW.successCB, queueWWW.apiFailureCB, queueWWW.layerFailureCB)); } We are waiting for request until we receive either that the request is done, there has been an error, or the request has timed out private IEnumerator WaitForRequest(WWW www, Callback successCallback = null, Callback apiFailureCallback = null, Callback layerFailureCallback = null) { int startLaunchRequestTime = ServerTime.instance.getRealGameTime(); while (!www.isDone && www.error == null && ((ServerTime.instance.getRealGameTime() - startLaunchRequestTime) < REQUEST_TIMEOUT)) { yield return www; } LaunchCallback cb = new LaunchCallback(); cb.www = www; cb.successCB = successCallback; cb.apiFailureCB = apiFailureCallback; cb.layerFailureCB = layerFailureCallback; if ((ServerTime.instance.getRealGameTime() - startLaunchRequestTime) >= REQUEST_TIMEOUT) { cb.timeOutError = true; } _launchCallbacks.Add(cb); } ------------------------------------------------------------------- II°) And then, in the update function, where we request the results for the launchcallback, handle the callbacks, and dispose the WWW object: public void update() { // issue requests we have decided to issue int len = _launchCallbacks.Count; List callbackToDelete = new List(); for (int i=0; i successCallback, Callback apiFailureCallback , Callback layerFailureCallback, bool timeOutError) { // handles success/ failure callbacks, not relevant here numberRequestInProgress --; } ------------------------------------------------------------------- III°) The LauncCcallback class is just a container for the WWW object and its callbacks: public class LaunchCallback { public Callback successCB; public Callback apiFailureCB; public Callback layerFailureCB; public WWW www; public bool hasTransaction; public bool timeOutError = false; public void dispose() { Debug.Log (" DISPOSING WWW object " + www.url ); www.Dispose(); successCB = null; apiFailureCB = null; layerFailureCB = null; } } ------------------------------------------------------------------- When I run the project on IOS, I get the debug output of DISPOSING WWW object " + www.url, but the leak instrument tells me that the issueRequest function has leaked several strings, dictionary etc etc, as if the WWW has not been disposed: http://imgur.com/RWBbYwH I really don't know what's going on, because I do pass in the dispose function of the launchcallback. Is there any references that could lead the WWW object to not be disposed? Many thanks, Down

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>