-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Conversation
CLAs look good, thanks! |
14c1144
to
0ec65a1
Compare
… cache `mdUtil`'s custom `cacheFactory` factory, adds/removes keys when putting/removing a single key, but leaves `keys` untouched when calling `removeAll()` or `destroy()`. As a result, the following problems arise: - Keys of destroyed caches continue to take up memory. - The `keys()` method return incorrect results after calling `removeAll()` (i.e. it continues to return the old keys, although they are not present in the cache any more). This commit fixes these issues, by overriding the `removeAll` and `destroy` methods as well.
Previously, the `updateAll()` method relied on `$timeout` for scheduling a digest. This made the possible changes apply after the next rendering and could possibly lead to extra digests. This commit, replaces the call to `$timeout` with a call to `$evalAsync()`, which avoids an extra digest if one is already in progress and also applies the changes before the next rendering.
0ec65a1
to
0bdb399
Compare
In commit 6397040 `mdMedia` was moved out of the `sidenav` component and into `core`. The .spec file remained in the original folder though. This commit moves the 'media.spec.js` file to the correct location and adds more tests to more thoroughly cover `mdMedia`'s functionality.
/ping @ThomasBurleson (or anyone) |
|
||
cache._destroy = cache.destroy; | ||
cache.destroy = function() { | ||
keys = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gkalpak - think this is dangerous. Perhaps:
cache._destroy = cache.destroy;
cache.destroy = function() {
keys = {};
return cache._destroy();
};
is safer and allows subsequent calls to cache.put()
to work properly.
Even though semantically the
cache.put( )
should not be called aftercache.destroy( )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subsequent calls to put()
will not work correctly anyway, because the original put()
will fail after having called destroy()
. (put()
is not supposed to be called after destroy()
.)
var cache = $mdUtil.cacheFactory('test');
cache.destroy();
cache.put('key', 'value'); // Throws an error regardless of the value of `keys`
So, having keys = null
helps GC (instead of having to keep a reference to an empty object around). But, it's impact should be minimal (even more so considering destroy()
is rarely used currently).
This PR contains some improvements to
mdMedia
, split-up in 3 commits as follows:fix(mdUtil): remove/delete cacheFactory keys when clearing/destroying cache:
mdUtil
's customcacheFactory
factory, adds/removes keys when putting/removing a single key, but leaveskeys
untouched when callingremoveAll()
ordestroy()
. As a result, the following problems arise:keys()
method return incorrect results after callingremoveAll()
(i.e. it continues to return the old keys, although they are not present in the cache any more).This commit fixes these issues, by overriding the
removeAll
anddestroy
methods as well.fix(mdMedia): avoid unnecessary digest and make changes apply quicker:
Previously, the
updateAll()
method relied on$timeout
for scheduling a digest. This made the possible changes apply after the next rendering and could possibly lead to extra digests.This commit, replaces the call to
$timeout
with a call to$evalAsync()
, which avoids an extra digest if one is already in progress and also applies the changes before the next rendering.test(mdMedia): add more tests and move .spec file to correct location:
In commit 6397040
mdMedia
was moved out of thesidenav
component and intocore
. The .spec file remained in the original folder though.*This commit moves the 'media.spec.js
file to the correct location and adds more tests to more thoroughly cover
mdMedia`'s functionality.* Since this commit, the file has been moved ot the right location in cfd48f8.