Memory Leak, SignalR in realtime webapplication - json

My application connects to a SignalR-hub, and it receives about 15 json-files per minute. For every json-file with a geolocation, a marker gets placed on a sphere in the 3D WebGL-scene, and gets stored in an object {}. When the objectlist reaches 100 items, the application deletes the first item in the objectlist, and deletes the corresponding marker from the scene.
But still, there is a huge memory leak, and when I hit about 200 events, the application crash.
Are the json-files being stored somewhere, and are causing the memory leak?

Though this is not the solution, but I will suggest you to use Ants Profiler to see if there is any memory leak issues in your application.
I will suggest you to derefernce all the listitem in the generic list after it is no use. This is the major cause of memory leaking.
Beware of concatenating strings, use stringbuilder as much as possible.

I am working on the same issue. I had no memory leaks before implementing signalr and now have a fairly significant one. I can disable the signalr in my app and the leak goes away. I'm on version 2.2.0 of signalr (the most current version from Nuget. The only thing that could be hanging up in memory from my code point of view is the event handler. At least that's the only thing I'm creating on the client side.

Related

Chrome garbage collector going crazy

Using Version 48.0.2564.109 m.
We have a javascript web app (built with ExtJS). In Chrome, when we leave our app sitting there for a while, the GC starts going nuts. In Task Manager, you can see the CPU constantly spinning around 25%.
I took timeline snapshots and CPU profiles, and you can see the GC, about 10 times a seconds, try to collect memory, but collects 0B.
Our app is a large enterprise application and does use quite a bit of memory and updates the screen periodically.
But, there is absolutely no javascript code running during this time. So I can't see that it is something our app is actively doing
Does anyone know what could be triggering this?
It is killing performance of our app.
Also, it only happens when our tab is active. If you switch to a different tab, the CPU dies down and the GC stops.
Is there other data I need to collect to help determine this?
What is your app current JS heap size? You can check it by collecting timeline and enabling memory check box.
It looks like your app is close to the V8 memory limit, so V8 is trying to free some memory. If it is expected for the app to use that much memory, you can increase the limit on your host with something like: --js-flags="--max-old-space-size=2048"
Otherwise it might be just a memory leak in your code. Use heap profiler to hunt it down.

Do I Have a Memory Leak / Garbage Collection Bug?

I'm building an Air application, which, due to the workflow of the animators, needs to load a lot of external swf files.
I load them all via FileStream / Loader Objects at the boot process and then store them in an object for further use.
The instant they get loaded, I use a gotoAndStop(1) command to make them stop looping (the original files have no scripts whatsoever).
After the load process I can see the system memory go slowly but consistently up.
When I manually invoke Garbage Collection with the System.gc() command,
the memory gets cleared again.
If I let the application run for hours it seems the Garbage Collector does not run.
Any ideas what the problem might be? Or should I just forget about it and just occasionally run System.gc() manually?
Thanks a lot!
The Garbage Collector will only run when it needs to, so it is entierly possible that it would go a very long time before running (especially if you have a lot of RAM available).
The important thing is the memory is cleared when it is run. This tells me that you don't have a leak, as it can be cleared up.
Also, how are you measuring the system memory? If you are doing it through Task Manager those numbers aren't really to be relied upon.
I recommend Process Explorer . Monitor the 'Private Bytes' column instead.

Understanding 'Native Memory profiling' in Chrome developer tools

I am building an application with a simple search panel with few search attributes and a result panel. In the result panel, I am rendering the data in a tabular form using Slickgrid.
After few searches (AJAX call to server), the page gets so much loaded and it eventually crashes after sometime. I have checked the DOM count and the JavaScript heap usage for possible memory leaks. I couldn't find anything wrong there. However, when I ran the experimental native memory profiler, I see that the "JavaScript external resource" section uses 600+ MB memory. On running the garbage collector, it is getting down to few MBs. I have couple of questions here:
What contributes to the "JavaScript external resource" section? I thought it corresponds to the JSON data / JavaScript sources which gets transferred from the server. FYI, the gzipped JSON response from the server is ~1MB.
Why is Chrome not releasing the memory pro-actively instead of crashing the page? Again, when I manually run the garbage collector, it is releasing the memory used by "JavaScript external resources".
How do I fix the original problem?
JS Heap Profiler makes a snapshot of the objects in the javascript but javascript code may use native memory with help of "Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array" and "Float64Array".
So when you take a snapshot it will have only small wrappers that point to native memory blocks.
Unfortunately heap snapshot does not provide data about the native memory that was used for these kind of objects.
Native heap snapshot is able to count that memory and now we know that the page uses native memory via an array or via an external string.
I'd like to know how did you check that the page has no memory leaks? Did you use three snapshot technique or just checked particular objects?
Tool to track down JavaScript memory leak

AS3 memory leak

I've been working on a library, and have run into a problem with application memory.
I created a class called FileManager which allows the user to call a function called loadNewFiles - this function opens a multi-file selection dialog and stores each FileReferenceList in a vector. I can call the removeList function at any time and remove that list and clear any memory and listeners allocated to that list, so all's well there.
I created another class called UploadManager, which takes an array of FileReference objects and uploads them to a URL via the uploadFiles function. The memory leak appears to be here. When you call this function, it adds the appropriate event listeners and calls the upload function. If the upload fails or the upload is finished, it removes the listeners and clears the vector it has been waiting in.
after the upload manager finishes uploading the files, I call the removeFiles function in FileManager (which, remember, worked perfectly before) and... Nothing happens. The files are removed from both vectors, the listeners are removed from both files, but the memory stays allocated. This obviously has potential to cause problems along the road, as there's no limit to the number of files, uploads, etc. available through the library.
classes:
FileManager
UploadManager
Implementation
It sounds like from your example that the UploadManager still has a reference to the files either from the vector passed into uploadFiles, or some other object in the game still has a reference.
Also note, System.gc() only works on the debug version of the flash player.
So you can't depend on it for an architectural design choice. It works for unit testing memory intensive operations when you need to see the consumption of ActionScript memory "on demand".
In a production product, the ActionScript Virtual Machine is very active in detecting when and where to garbage collect. Most would say it happens right when you don't want it to.
Try profiling the application and looking at the "cumulative instances" vs. "instances", as well as the "cumulative memory" vs. "memory" for the objects in question (i.e. FileReference).
You can force garbage collection during runtime in the Profile View to get a realistic idea of how much memory is actually freed when garbage collection takes place in the Release version.

Why does Flash Builder 4.6 Profiler seem to leak Strings, whereas Debug mode GC's as expected

While unit profiling my classes I noticed that the String class endlessly accumulates (eating up over 90% of the memory in my sizable app). Luckily this is only while running in Profiler mode of Flash Builder 4.6. In debug or deployment (as AIR) memory usage levels off as expected using embedded on-screen memory profilier (Mr Doobs Stats).
To verify I made a test app that was simply a URLLoader continuously loading a text file. When running in Profilier mode using URLLoaderDataFormat.String the String data is never GC'd and grows continuously whereas using URLLoaderDataFormat.BINARY the data is nearly immediately GC'd and stays level.
I hesitate to call this a bug, because possibly it's necessary part of the way the Profilier works… but perhaps this is abnormal for the Profiler? This is the essence of my StackOverflow inquiry.
At any rate, this burned up a couple work-days for me, so if you're Googling wondering why the String class is growing like crazy and never getting GC'd consider measuring your apps memory usage outside the Profilier to verify. In my case I was mislead into thinking I had run into some problem with Master Strings — though it's good understand Master Strings and their impact on memory (see:) don't get mislead like I did.