I have the requirement to update an image in the App over and over again (displaying some generated data).
But after several intervals the app crashes with out of memory.
I'm updating the image with this line:
(that.detailImage.nativeElement).src = DummyImage.image1;
setting the image as base64-String. I already tried using res:// and external references and even local files. The problem stays: it keeps the memory.
Reducing the size of the image helps only to delay the crash, I even got the crash with an 1kb image, but it took some minutes.
You can find the "running" code at:
https://bitbucket.org/WarEagle/implementationproblems/src/944eedf10a14d60ec421e274760b3c2c3d9ae9a1/ImageTest/?at=master
I'm really interested in understanding what I'm doing wrong. Every solution I found so far said: "make the image smaller" but this only delays the problem.
Greetings
Torsten
p.s. don't wonder about the = undefined in the example-code, this is done because I'm setting the same image over and over again, than it works, but if I update the src-property with another image, it crashes, for this example I used = undefined to reproduce the problem without uploading thousands of images for changing them around.
Related
This question refers to Codename One only.
I have a Form with a Tabs and each tab can contain an arbitrary number of images (taken from the Gallery).
Result: after few images (eight images from the gallery), on my Android device I get:
java.lang.OutOfMemoryError: Failed to allocate a 5683356 byte allocation with 1845080 free bytes and 1801KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:737)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:703)
at com.codename1.impl.android.c.b(AndroidImplementation.java:2037)
at com.codename1.r.z.a(Image.java:531)
at cool.teammate.apps.frontend.b.e.a$1.a(BasePageForm.java:208)
at com.codename1.r.l.b.a(EventDispatcher.java:349)
at com.codename1.impl.android.c.a(AndroidImplementation.java:7336)
at com.codename1.impl.android.CodenameOneActivity$6.run(CodenameOneActivity.java:527)
at com.codename1.r.r.n(Display.java:1298)
at com.codename1.r.r.l(Display.java:1242)
at com.codename1.r.r.k(Display.java:1130)
at com.codename1.r.aq.run(RunnableWrapper.java:120)
at com.codename1.impl.b$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:776)
Also iOS crashes, but I haven't the log.
Each image is scaled before showing (using the class FixedSizeButton, that I reported in this question). Any suggestion?
I guess that the dispose() method of Image can be useful, but it's written to "DO NOT CALL THIS METHOD UNLESS YOU KNOW WHAT YOU ARE DOING". Is it so problematic? For example, can it help if I dispose an Image after saving it to file and/or after scaling?
I also guess that System.gc() can be useful.
However, if few photos are so problematic... how can I make a photo gallery inside a Form without this kind of issues? Same problem to load hundreds of photo post inside an InfiniteContainer...
Note that the memory issue happens regardless if I insert the images as icon of a Button or as filled background of the Button.
Thank you for your suggestion.
You don't need to call dispose() or gc() for a proper application. You're trying to load a 5mb image which I'm assuming is a 5mb JPEG. That's probably from a 9+ mega pixel camera which means the decompressed size would be roughly 9 x 4 == 36MB!
So 36 x 8 = 288mb of RAM.
this.image = Image.createImage(this.imageWidth, this.imageHeight, 0xFFdddddd);
What's imageWidth/Height?
You might be taking a lot of RAM here...
this.setIcon(this.image);
EasyThread scalingThread = EasyThread.start("FixedSizeButton-ScalingImg-" + fileName);
Since you're creating multiple threads you might have all 8 images in RAM at once.
A better way is to use one image scaling thread. An even better approach is avoiding scaled altogether and using ImageIO to scale the image without loading it into RAM.
I am stuck with the memory increment of my application and as it is single page I can't even reload it. After running my application for around 5-6 hour memory size is reaching around 600mb from initial loading i.e 120mb and we did some fixed for this like making the ref to null in the componentWillunMount() and memory has reduced to 400 mb after the same testing for same time but still I can see there are lot many detached element, definitely it caused by some other parts of the code, in the snapshot file which we can take from chrome inbuilt functionality. So is there any way that I can remove all the detached-element while leaving the certain page or why don't browser removed this from memory as the detached-element is retaining some size of the memory ?
DOM node can only be garbage collected when there are no references to it from either the page's DOM tree or JavaScript code.
I suggest you take a look at your code and see if there are functions running not when you want it. If you use react or similar frameworks, you have to be careful with their lifecycle (important!).
Also here https://developers.google.com/web/tools/chrome-devtools/memory-problems/
There are many useful information, such as
- Investigate memory allocation by function
- Spot frequent garbage collections
So is there any way that I can remove all the detached-element while leaving the certain page or why don't browser removed this from memory
I cant offer any more accurate assumption or suggestion if what we have is I use javascript information. Countless consequences from countless combination of libraries, stacks and techniques make this impossible to guess.
I save the point clouds of a scene and its quaternion in a pcl file.
First, I've only used pose w.r.t to device start (see second image) to get the quaternion. I've discovered a drifting problem which I mentioned here.
Therefore, I learned the scene with area learning (see first image) by walking around the table.
After that, I'm loading the area description file (ADF) to overcome the drifting. I wait for the first loop closure/localization in the onPoseAvailable callback.
Then in the onXyzIjAvailable callback I use its timestamp to get a valid pose w.r.t to the ADF origin (baseFrame = COORDINATE_FRAME_AREA_DESCRIPTION and targetFrame = COORDINATE_FRAME_DEVICE).
And I save the poseAtTime(xyzIj.timestamp) and the xyzIj in a *.PCD file.
But, the drifting seems to get even worse (see third image). It's better oriented to the origin, but the point clouds aren't that
close as in the image without adf.
Do I something wrong?
Is there any way to improve this?
You should set up the pose callback such that only poses with respect to ADF base are returned - poses with respect to start of service should not be returned - drift will not go away, but it will become minimal and will autocorrect - the ADF needs to be well trained to keep up the pose return rate.
I am working on a project where we were asked to "patch" (they don't want a lot of time spent on development as they soon will replace the system) a system implemented under ExtJS 4.1.0.
That system is used under a very slow and non-stable network connection. So sometimes the stores don't get the expected data.
First two things that come to my mind as patches are:
1. Every time a store is loaded for the first time, wait 5 seconds and try again. Most times, a page refresh fix the problem of stores not loading.
Somehow, check detect that no data was received after loading a store and, try to get it again.
This patches should be executed only once to avoid infinite loops or unnecessary recursivity, given that it's ok that some times, it's ok that stores don't get any data back.
I don't like this kind of solutions but it was requested by the client.
This link should help with your question.
One of the posters suggests adding the below in an overrides.js file which is loaded in between the ExtJs source code and your applications code.
Ext.util.Observable.observe(Ext.data.Connection);
Ext.data.Connection.on('requestexception', function(dataconn, response, options){
if (response.responseText != null) {
window.document.body.innerHTML = response.responseText;
}
});
Using this example, on any error instead of echoing the error in the example you could log the error details for debugging later and try to load again. I would suggest adding some additional logic into this so that it will only retry a certain number of times otherwise it could run indefinitely while the browser window is open and more than likely crash the browser and put additional load on your server.
Obviously the root cause of the issue is not the code itself, rather your slow connection. I'd try to address this issue rather than any other.
I have an application that essentially shows a slide show of images from a file. The loading of the images slows down over time. Putting in some timing code, I've identified the slowing line of code as the ConvertFromString line below:
var imgSrcConverter = new ImageSourceConverter();
imgSrc = (ImageSource) imgSrcConverter.ConvertFromString(imgFilePath);
Over the course if 15 hours, the execution of this line went from taking ~70ms to >400ms.
Can anyone offer any suggestions as to why this would happen and what can be done to prevent and/or improve the situation?
Could you load the images into memory on startup, and then just cycle through them?