Titanium SDK version: 1.7.0
iPhone SDK version: 4.2
I am developing an iOS app and I monitor the memory usage for each window And it keeps decreasing for every screen.
What is consuming memory in general? I use views, tables and XHR data.
How can I release memory / decrease usage on each window?
Thankful for all input!
Considering you are dealing with JavaScript being translated to Objective-C and can't necessarily write a native solution without using modules you could start by setting window variables to null (myJsWindowVar = null;), or delete those variables using delete (delete myJsWindowVar;). Personally I think setting variables to null will better translate to the suggested Objective-C best practice which is to set a pointer reference to null and prevent orphaned objects from hanging around.
Make sure you close unused windows and clear our any references to native objects you no longer need in the app.
// create a window object
var aWindow = Ti.UI.createWindow();
var aLabel = Ti.UI.createLabel({ text : "Hey" });
aWindow.add(aLabel);
aWindow.open();
// done with window
aWindow.close();
aWindow = null;
aLabel.null;
Check out this presentation from the Appcelerator Codestrong conference for more details.
Related
I'm developing an Angular/ Typescript application that makes use of the Autodesk Forge viewer to display building models on smartphones and tablets. The application itself runs smoothly, but the problem occurs when I close the application. After closing the application, I notice that hardly any memory gets released, as can be seen in the image below (I close the application around the 8 seconds mark) and after opening the viewer for two or three more times it will run out of memory and crash.
When I close the application, I call both the tearDown() and the finish() method as described in the Forge docs and set all possible references to the Forge viewer to null, but they memory leak still persists. This is the main chunk of my viewer code:
this.initOptions = {
path: 'url to model',
env: 'Local',
useADP: false,
extensions: [],
};
Autodesk.Viewing.Initializer(this.initOptions, () => {
this.onEnvInitialized();
});
private onEnvInitialized() {
this.viewer = new Autodesk.Viewing.Private.GuiViewer3D(this.viewerContainer.nativeElement, {});
this.viewer.initialize();
this.viewer.loadModel(this.initOptions.path, {}, (doc) => {
// further forge viewer execution here
}, (errorMsg) => {
console.log(errorMsg);
});
}
public ngOnDestroy() {
// remove all eventlisteners
this.initOptions = null;
this.viewer.tearDown();
this.viewer.finish();
this.viewer = null;
}
Is this a known issue and/ or is there some way I can manually release the memory used by the Forge viewer after closure? (It is part of the use case that I have to be able to open more than three viewers after each other in one session.)
Update [19-09-17]
I tried opening my viewer in a fresh, empty angular2 project, and although less memory is being used in general, the same behavoir of not clearing the memory still applies, as can be seen here. I do notice that the event listeners are drastically reduced now. I also updated the Forge Viewer to version 2.17, and the same issue still applies here as well.
The problem remains with version 3.3.5 of the forge viewer. The issue however seems a bit deeper. It looks like when calling viewer.finish() it doesn't release any GPU memory used for the textures.
We call this function everytime you navigate away from the page with the viewer as angular destroys the canvas in the DOM. I would expect .finish to also remove the textures from the memory. Is there any other function that can be called to completely unload any model and textures?
Here are some screenshots where you can see the memory buildup.
Initial initialisation of the page
after returning to this page after closing it
after returning to this page after closing it a third time
What version of the Viewer are you currently using? Here you can see a list of the recent changes on the viewer version, v2.17 has a Memory Limit ON by default.
https://developer.autodesk.com/en/docs/viewer/v2/overview/changelog/
Also the version of the viewer can be checked if it is not been defined from the console by typing LMV_VIEWER_VERSION
I was using Properties.Settings.Default to store persistent data between sessions. For example, I was using Properties.Settings.Default.mute to store a boolean of whether or not to mute sounds.
I went online and it recommends to use Windows.Storage.ApplicationData.Current.LocalSettings.Values. So I try setting Windows.Storage.ApplicationData.Current.LocalSettings.Values["mute"] and using that, but that actually crashes the debugger, so I can't even debug whatever the issue is.
You have to set some data in Windows.Storage.ApplicationData.Current.LocalSettings.Values["mute"] before use it, for example:
Windows.Storage.ApplicationData.Current.LocalSettings.Values["mute"] = true;
(or false or an other value ) the you can get it like this
var t = Windows.Storage.ApplicationData.Current.LocalSettings.Values["mute"];
As you all know Coded ui playback can be kind of slow depending on the controls you're querying.
To try and solve this issue I am looking at adding some multithreading capabilities to the test.
Here is a for loop which works successfully, now converted to a Parallel.For - only the control cannot be found (not at all).
Parallel.For(0, totalItems, (i, loopState) =>
{
DxLookup.OpenPopup();
var cell = _popupGrid.GetCell(viewName, column.ColumnName, i);
cell.DrawHighlight();
if (cell.ValueAsString == item)
{
found = true;
loopState.Stop();
}
});
The code fails on the DxLookup.OpenPopup - because the control is not found. Looks like it could be thread related.
How is it possible to access a test control from another thread then?
I am not too sure about Coded UI playback supports multi-threading capabilities check this link for playback related information
Configure Playback
you may try come other techniques to speedup the playback
what kind of app are you trying to test? if it's a winforms app multithrreading is problematic.
try testing wheter you can locate tha main app window or any kind of control. if not you'll know it's a threading problem. if you can locate any kind of control just not the desired control you'll be able to tweak the search configurations to loacte the control.
hope this helps
I am using Flash builder actionscript 3 Flex mobile.
I have a very heavy function that loads data from the local device and creates many graphic elements. While this function runs, the device freezes for 6 seconds or so.
I want to show a progress bar and let the device continue working, is there any way I can use threading to do this ? Other ideas are also welcome.
Thanks, Koby.
You know that at which function application getting freeze. Before that function call a progress bar. Create a progress bar in a pop up mode & call it. After 6 seconds(Not recommended) or getting the data just call removeallpopups() method. So now you can set the label in progress bar as "Loding..."
Sample code
<mx:ProgressBar id="sampleProgressBar" styleName="Calib16Blue"
indeterminate="true" labelPlacement="left"
label="{theMessage}"/>
Call this mxml by creating a pop up.
To do 'proper' muiltithreading you need to use the Worker Class (Documentation here), however the SQLConnection class and FileStream class have asynchronous methods that fit into the normal Actionscript event listener cycle and operate in "the background". Allowing the rest of the app to load when they're still pending.
Everytime I use AVSpeechSynthesizer to speak text Instruments reports a memory leak in the AXSpeechImplementation library. Here's the code I'm using to make the call:
AVSpeechUtterance *speak = [AVSpeechUtterance speechUtteranceWithString:text];
speak.voice = [AVSpeechSynthesisVoice voiceWithLanguage:#"en-US"];
speak.rate = AVSpeechUtteranceMaximumSpeechRate * .2;
[m_speechSynth speakUtterance:speak];
Here's the link to the Instruments screenshot
http://imageshack.com/a/img690/7993/b9w5.png
For what it is worth - yes, I see exactly the same 16byte leak on every utterance from the speech synthesizer. So either it is a leak in Apple's code or we are both making the same error somewhere!
Ali
I solved this by declaring the AVSpeechSynthesizer as a global variable
static let synth = AVSpeechSynthesizer()