Giter Site home page Giter Site logo

Comments (6)

bfattori avatar bfattori commented on May 13, 2024

Take a look at my alternative way to avoid bootstrapping Angular each time in issue #54

from golden-layout.

natcohen avatar natcohen commented on May 13, 2024

Thanks, but in my case bootstraping angular in each tab is necessary... Indeed, I use the tabs exactly as webbrowser tabs so my app can be opened many times (if I bootstrap it once, a lot of conflicts would appear (listeners, variables, etc...)!).

I started with iframes but got into troubles (#34) so I followed your advice and bootstrap each tab. This works great except for @media (#51) and the leaks.

from golden-layout.

joshribakoff avatar joshribakoff commented on May 13, 2024

Do you have hanging DOM nodes? In modern JS browsers, DOM nodes can have "retaining paths". For example if you have a reference var foo = jQuery('.foo'), and then you remove the element from the DOM but do not cleanup the JS variable "foo", you retain "hanging DOM nodes" in memory.

I'm not familiar with your particular issue, but this article helped me solve similar problems in other code - http://addyosmani.com/blog/taming-the-unicorn-easing-javascript-memory-profiling-in-devtools/

For example, you didn't mention if you tried to force GC in the devtools. GC only happens every so often, and memory may appear to steadily increase prior to a GC invocation, with no correlation to the presence/absense of memory leaks. GC can be delayed for a very long time due to any number of reasons such as the thread not being idle, or not enough garbage having accumulated yet, as far as I know the browser makes no guarantees about when the memory is actually free'd. Even after a GC cycle occurs or is forced, not all garbage may be processed. It may take multiple such cycles to free up all memory, as far as I know. Also, if you're able to compare snapshots before & after & find the specific DOM nodes or other type(s) of garbage that is left over, that should help expedite a fix for this.

I also second the notion about bootstrapping tabs multiple times. I've never encountered a need to bootstrap multiple apps, where I couldn't just write a new directive that wraps them into a single new app & bootstrap that 1x. It may work, its just not the "Angular" way IMO. If you need initialization logic, its best to insert a directive into each tab using the $compile service, and put the initialization logic in a directive's link/controller functions:

Here's a golden layout component:

myLayout.registerComponent( 'template', function( container, state ){
                $http.get(state.templateId, {cache:true}).success(function(html) {
                    html = $compile('<div>'+html+'</div>')($rootScope);
                    container.getElement().html(html);
                    container.on( 'resize', function(){
                        $(window).trigger( 'resize' );
                    });
                });
            });

Use like this:

var myLayout = new GoldenLayout({
                settings: {
                    showPopoutIcon : false
                },
                content: [{
                    type: 'row',
                    isClosable: false,
                    content: [{
                        type: 'component',
                        title: 'hello world!',
                        componentName: 'template',
                        componentState: { templateId: 'foo/bar.html' },
                        isClosable: false
                    }]
                }]
            });

It should fetch the template 1x per session via $http & cache it. It will "bring to life" any directives found in the template via running it through $compile service, and bind the resize events which should help with any AngularJS/jQuery plugins.

from golden-layout.

Jmales avatar Jmales commented on May 13, 2024

@natcohen Did you manage to solve this?

from golden-layout.

natcohen avatar natcohen commented on May 13, 2024

@Jmales No...

from golden-layout.

Jmales avatar Jmales commented on May 13, 2024

@natcohen Ty for the answer. How come it was closed then?
2 years later and I'm also having memory leaks with GL when using angular: #216

from golden-layout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.