Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Closed $modal reference kept in memory but not in DOM? (>=0.9.0 only) #1778

Closed
gregtzar opened this issue Feb 11, 2014 · 5 comments
Closed

Comments

@gregtzar
Copy link

It looks as though a reference to a closed $modal is being kept in memory, even when the modal is removed from the DOM. This happens when I use $rootScope.$on() in the modal's controller.. I'm not sure if it happens without it.

I can reproduce in >=0.9.0 but not <=0.8.0 with latest Chrome browser.

Plunkr: http://plnkr.co/edit/ahB5ScVghWr1ZRcvPWlz

  1. Open console
  2. Click the Launch button to launch overlay
  3. Click the Close button in overlay to close it
  4. Click the CloseAll button to send a message to any open overlays (there are none)
  5. See uncaught exception from ui.bootstrap
  6. Swap out the 0.9.0 script tag for 0.8.0 and run the procedure again.. no uncaught exception

Update: On second thought it looks as though the problem might be with the $on listener not being cleaned up.

@gregtzar
Copy link
Author

Note also that if you launch/close the modal multiple times, and then click on CloseAll, multiple exceptions are generated (one for every modal).

@gregtzar gregtzar reopened this Feb 11, 2014
@chrisirhc
Copy link
Contributor

The CloseAll listeners aren't being cleaned up because you're adding them to the $rootScope. Listeners added to the $rootScope will never be removed unless you remove them manually. What you probably wanted to do is to listen on the $scope of the modal for the CloseAll event.
http://plnkr.co/edit/RENEj0jPaugsZGzGOmRK?p=preview

Also note that you can use $modalStack.dismissAll as of 0.10 .

@chrisirhc
Copy link
Contributor

Just re-looked into this and found the problem in your code. Please re-open if this issue isn't resolved.

@gregtzar
Copy link
Author

@chrisirhc Yep what you said about having the listener on $rootScope makes sense. I was using $rootScope rather than $scope for performance reasons, so that I can $emit down the tree (which in the case of $rootScope ends at $rootScope) rather than $broadcast up it. But I could always clean up these listeners myself. Is there a way to override or extend the close or destroy method triggered by $modalStack.dismissAll? I need different modals to respond differently to the 'close all' request.

Still I wonder why it is these listeners seem to be automatically cleaned up in <=0.8.0 but not in >=0.9.0. Perhaps it is actually a bug in <=0.8.0 where they should not be getting cleaned up but somehow they are.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants