Skip to content

Commit

Permalink
fix(mem-leak): Fix potential memory leaks. (#15309)
Browse files Browse the repository at this point in the history
  • Loading branch information
MayaKirova authored Feb 10, 2025
1 parent ca888ee commit 9b18b5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
Output,
Renderer2,
booleanAttribute,
AfterContentInit
AfterContentInit,
OnDestroy
} from '@angular/core';
import { mkenum } from '../../core/utils';
import { IBaseEventArgs } from '../../core/utils';
Expand Down Expand Up @@ -46,7 +47,7 @@ export type IgxButtonType = typeof IgxButtonType[keyof typeof IgxButtonType];
selector: '[igxButton]',
standalone: true
})
export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterContentInit {
export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterContentInit, OnDestroy {
private static ngAcceptInputType_type: IgxButtonType | '';

/**
Expand Down Expand Up @@ -92,6 +93,12 @@ export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterC
*/
private _selected = false;

private emitSelected() {
this.buttonSelected.emit({
button: this
});
}

/**
* Gets or sets whether the button is selected.
* Mainly used in the IgxButtonGroup component and it will have no effect if set separately.
Expand Down Expand Up @@ -121,11 +128,11 @@ export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterC
}

public ngAfterContentInit() {
this.nativeElement.addEventListener('click', () => {
this.buttonSelected.emit({
button: this
});
});
this.nativeElement.addEventListener('click', this.emitSelected.bind(this));
}

public ngOnDestroy(): void {
this.nativeElement.removeEventListener('click', this.emitSelected);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,13 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterViewInit
private themeToken: ThemeToken
) {
this._theme = this.themeToken.theme;

const { unsubscribe } = this.themeToken.onChange((theme) => {
const themeChange = this.themeToken.onChange((theme) => {
if (this._theme !== theme) {
this._theme = theme;
this.cdr.detectChanges();
}
});

this._destroyRef.onDestroy(() => unsubscribe);
this._destroyRef.onDestroy(() => themeChange.unsubscribe());
}

/** @hidden */
Expand Down

0 comments on commit 9b18b5f

Please sign in to comment.