Skip to content

Commit

Permalink
fix(cdk:form,comp:icon): fix suspected memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Feb 1, 2024
1 parent 2405527 commit 7ce35d7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
18 changes: 17 additions & 1 deletion packages/cdk/forms/src/models/abstractControl.ts
Expand Up @@ -24,7 +24,7 @@ import {

import { isArray, isFunction, isNil, isPlainObject, isString } from 'lodash-es'

import { convertArray } from '@idux/cdk/utils'
import { convertArray, tryOnScopeDispose } from '@idux/cdk/utils'

import {
type AsyncValidatorFn,
Expand Down Expand Up @@ -608,6 +608,22 @@ export abstract class AbstractControl<T = any> {
current.pristine = computed(() => !this._dirty.value)
current.validated = computed(() => this._validated.value)

tryOnScopeDispose(() => {
current.controls = null
current.valueRef = null
current.errors = null
current.status = null
current.valid = null
current.invalid = null
current.validating = null
current.disabled = null
current.blurred = null
current.unblurred = null
current.dirty = null
current.pristine = null
current.validated = null
})

if (this._disabledFn) {
nextTick(() => {
watchEffect(() => {
Expand Down
17 changes: 16 additions & 1 deletion packages/components/icon/src/Icon.tsx
Expand Up @@ -5,7 +5,16 @@
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/

import { type CSSProperties, computed, defineComponent, normalizeClass, onMounted, ref, watch } from 'vue'
import {
type CSSProperties,
computed,
defineComponent,
normalizeClass,
onBeforeUnmount,
onMounted,
ref,
watch,
} from 'vue'

import { convertCssPixel, isNumeric } from '@idux/cdk/utils'
import { type IconConfig, useGlobalConfig } from '@idux/components/config'
Expand All @@ -24,6 +33,12 @@ export default defineComponent({
const root = ref<HTMLElement>()

onMounted(() => appendChild(props, config, root.value!))
onBeforeUnmount(() => {
if (root.value) {
clearSVGElement(root.value)
root.value = undefined
}
})

watch([() => props.name, () => props.iconfont], () => {
const rootElement = root.value
Expand Down

0 comments on commit 7ce35d7

Please sign in to comment.