0

I'm authoring a desktop web application using famo.us. The nature of the application is to run some animation based on user input and server responses.

After running the application for some time and inspect heap, it reveals that, every single famo.us object (surfaces, views) that is created is still in memory. I have ensured that there exist no references to any of these objects from my application, but, of no use.

Following is a sample code, which creates 4 surface objects (no further actions or animations). As my application does not hold reference to any of the Surface objects, I'm expecting these to be released, but, you can see there exists 4 Surface objects in heap (chrome profiling).

define(function(require, exports, module) {
    var Engine  = require("famous/core/Engine");
    var Surface = require("famous/core/Surface");
    var RenderController = require('famous/views/RenderController');

    var mainContext = Engine.createContext();
    function addSurface(){
        var surface = new Surface({
            size: [200, 200],
            content: "Hello World",
            classes: ["red-bg"],
            properties: {
                lineHeight: "200px",
                textAlign: "center"
            }
        });
        mainContext.add(surface);
    }
    addSurface();
    addSurface();
    addSurface();
    var surface = new Surface({
        size: [200, 200],
        content: "Hello World",
        classes: ["red-bg"],
        properties: {
            lineHeight: "200px",
            textAlign: "center"
        }
    });

    var rc = new RenderController();
    mainContext.add(rc);
    rc.show(surface);

    rc.hide();
    surface = null;
    mainContext = null;
    rc = null;

    Engine = null;
    Surface = null;
    RenderController = null;
});

Please help me figuring out what am I missing.

1 Answers1

0

I have no knowledge of your specific use-case and the technology you are using, but from my general knowledge about how GC works, here are a few possible reasons which may help you to narrow down your problem:

Reference escape
Even if you seem to free all references to the objects that you want to be collected, methods called in the meantime may pass references to these objects to globally-reachable data structures (e.g. static variables), which then would cause the objects to be still reachable from the GC roots.

Objects are eligible for collection, but no collection takes place
The objects may no longer be reachable from the GC roots, but still visible in your profiler, because no Garbage Collection (of the heap space in which they reside) has run. This may have various reasons, the simplest being that you have a marking collector and the heap space was not exhausted yet. If you have the option to encourage a garbage collection from your program, you could try that.

Reference cycle
If the objects reference each other in a cycle, a basic reference counting GC is unable to determine that these objects are garbage and could be freed.

Michael Schmeißer
  • 3,407
  • 1
  • 19
  • 32