@@ -65,17 +65,8 @@ exports.compile = function (el, options, partial, host) {
65
65
if ( nodeLinkFn ) nodeLinkFn ( vm , el , host )
66
66
if ( childLinkFn ) childLinkFn ( vm , childNodes , host )
67
67
} , vm )
68
-
69
- /**
70
- * The linker function returns an unlink function that
71
- * tearsdown all directives instances generated during
72
- * the process.
73
- *
74
- * @param {Boolean } destroying
75
- */
76
- return function unlink ( destroying ) {
77
- teardownDirs ( vm , dirs , destroying )
78
- }
68
+ //
69
+ return makeUnlinkFn ( vm , dirs )
79
70
}
80
71
}
81
72
@@ -93,6 +84,30 @@ function linkAndCapture (linker, vm) {
93
84
return vm . _directives . slice ( originalDirCount )
94
85
}
95
86
87
+ /**
88
+ * Linker functions return an unlink function that
89
+ * tearsdown all directives instances generated during
90
+ * the process.
91
+ *
92
+ * We create unlink functions with only the necessary
93
+ * information to avoid retaining additional closures.
94
+ *
95
+ * @param {Vue } vm
96
+ * @param {Array } dirs
97
+ * @param {Vue } [parent]
98
+ * @param {Array } [parentDirs]
99
+ * @return {Function }
100
+ */
101
+
102
+ function makeUnlinkFn ( vm , dirs , parent , parentDirs ) {
103
+ return function unlink ( destroying ) {
104
+ teardownDirs ( vm , dirs , destroying )
105
+ if ( parent && parentDirs ) {
106
+ teardownDirs ( parent , parentDirs )
107
+ }
108
+ }
109
+ }
110
+
96
111
/**
97
112
* Teardown partial linked directives.
98
113
*
@@ -183,10 +198,7 @@ function teardownDirs (vm, dirs, destroying) {
183
198
184
199
// return the unlink function that tearsdown parent
185
200
// container directives.
186
- return function rootUnlinkFn ( ) {
187
- teardownDirs ( parent , parentDirs )
188
- teardownDirs ( vm , selfDirs )
189
- }
201
+ return makeUnlinkFn ( vm , selfDirs , parent , parentDirs )
190
202
}
191
203
192
204
/**
0 commit comments