Skip to content

Commit edc4068

Browse files
Internal: Solve some memory leak issue in app and tests (#1029)
1 parent 71afdc2 commit edc4068

20 files changed

Lines changed: 204 additions & 114 deletions

app/components/application/browse/application-list.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export class ApplicationListComponent extends ListOrTableBase implements OnInit,
6767

6868
public ngOnDestroy() {
6969
this._subs.forEach(x => x.unsubscribe());
70+
this.data.dispose();
7071
}
7172

7273
@autobind()

app/components/application/details/application-details.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class ApplicationDetailsComponent implements OnInit, OnDestroy {
6666

6767
public ngOnDestroy() {
6868
this._paramsSubscriber.unsubscribe();
69+
this.data.dispose();
6970
}
7071

7172
@autobind()

app/components/job/action/add/pool-picker.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class PoolPickerComponent implements ControlValueAccessor, OnInit, OnDest
6060

6161
public ngOnDestroy() {
6262
this._subs.forEach(x => x.unsubscribe());
63+
this.poolsData.dispose();
6364
}
6465

6566
public writeValue(poolInfo: any) {

test/app/components/job/details/job-progress-status/job-progress-status.component.spec.ts renamed to app/components/job/details/job-progress-status/job-progress-status.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { ComponentFixture, TestBed } from "@angular/core/testing";
33
import { By } from "@angular/platform-browser";
44
import { Observable } from "rxjs";
55

6-
import { JobProgressStatusComponent } from "app/components/job/details/job-progress-status";
76
import { Job, JobTaskCounts, Node, Pool } from "app/models";
87
import { JobService, NodeService, PoolService } from "app/services";
98
import { PollService } from "app/services/core";
109
import { click } from "test/utils/helpers";
1110
import { MockEntityView, MockListView } from "test/utils/mocks";
1211
import { GaugeMockComponent } from "test/utils/mocks/components";
12+
import { JobProgressStatusComponent } from "./job-progress-status.component";
1313

1414
@Component({
1515
template: `<bl-job-progress-status [job]="job" [poolId]="poolId"></bl-job-progress-status>`,
@@ -59,7 +59,7 @@ describe("JobProgressStatusComponent", () => {
5959
};
6060

6161
pollServiceSpy = {
62-
startPoll: () => ({}),
62+
startPoll: () => ({destroy: () => null}),
6363
};
6464

6565
TestBed.configureTestingModule({

app/components/job/details/job-progress-status/job-progress-status.component.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component, Input, OnChanges, OnDestroy } from "@angular/core";
22
import { List } from "immutable";
3-
import { Subscription } from "rxjs";
43

54
import { GaugeConfig } from "app/components/base/graphs/gauge";
65
import { Job, JobTaskCounts, Node, Pool } from "app/models";
@@ -15,11 +14,9 @@ import "./job-progress-status.scss";
1514
templateUrl: "job-progress-status.html",
1615
})
1716
export class JobProgressStatusComponent implements OnChanges, OnDestroy {
18-
@Input()
19-
public job: Job;
17+
@Input() public job: Job;
2018

21-
@Input()
22-
public poolId: string;
19+
@Input() public poolId: string;
2320

2421
public nodes: List<Node> = List([]);
2522
public pool: Pool;
@@ -38,7 +35,6 @@ export class JobProgressStatusComponent implements OnChanges, OnDestroy {
3835
private poolData: EntityView<Pool, PoolParams>;
3936

4037
private _polls: PollObservable[] = [];
41-
private _subs: Subscription[] = [];
4238

4339
constructor(
4440
poolService: PoolService,
@@ -54,20 +50,20 @@ export class JobProgressStatusComponent implements OnChanges, OnDestroy {
5450

5551
this.updateGaugeOptions();
5652

57-
this._subs.push(this.poolData.item.subscribe((pool) => {
53+
this.poolData.item.subscribe((pool) => {
5854
this.pool = pool;
5955
this.maxRunningTasks = pool ? pool.targetNodes * pool.maxTasksPerNode : 1;
6056
this.updateGaugeOptions();
61-
}));
57+
});
6258

63-
this._subs.push(this.data.items.subscribe((nodes) => {
59+
this.data.items.subscribe((nodes) => {
6460
if (this.nodes.size !== nodes.size) {
6561
this.poolData.refresh();
6662
}
6763
this.nodes = nodes;
6864
this.countRunningTasks();
6965
this.updateGaugeOptions();
70-
}));
66+
});
7167

7268
this._polls.push(this.data.startPoll(refreshRate));
7369

@@ -89,7 +85,7 @@ export class JobProgressStatusComponent implements OnChanges, OnDestroy {
8985

9086
public ngOnDestroy() {
9187
this._polls.forEach(x => x.destroy());
92-
this._subs.forEach(x => x.unsubscribe());
88+
this.data.dispose();
9389
this.poolData.dispose();
9490
}
9591

app/components/node/connect/node-connect.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ export class NodeConnectComponent implements OnInit {
5757
public ngOnInit() {
5858
const data = this.nodeService.listNodeAgentSkus();
5959
data.fetchAll().subscribe(() => {
60-
data.items.first().subscribe((agentSkus) => {
60+
data.items.take(1).subscribe((agentSkus) => {
6161
this.agentSkus = agentSkus;
6262
this.windows = PoolUtils.isWindows(this.pool, agentSkus);
63+
data.dispose();
6364
});
6465
});
6566
this._loadConnectionData();

app/components/pool/action/add/app-license-picker.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, ViewChild, ViewContainerRef, forwardRef } from "@angular/core";
1+
import { Component, OnInit, ViewChild, forwardRef } from "@angular/core";
22
import {
33
ControlValueAccessor, FormControl, NG_VALIDATORS, NG_VALUE_ACCESSOR, Validator,
44
} from "@angular/forms";
@@ -37,7 +37,6 @@ export class AppLicensePickerComponent implements ControlValueAccessor, OnInit,
3737
private _eulaRead: boolean = false;
3838

3939
constructor(
40-
private viewContainerRef: ViewContainerRef,
4140
private dialog: MatDialog) {
4241
}
4342

@@ -103,7 +102,6 @@ export class AppLicensePickerComponent implements ControlValueAccessor, OnInit,
103102

104103
public viewEula(license: ApplicationLicense) {
105104
const config = new MatDialogConfig();
106-
config.viewContainerRef = this.viewContainerRef;
107105
const dialogRef = this.dialog.open(LicenseEulaDialogComponent, config);
108106
dialogRef.componentInstance.license = license;
109107
}

app/components/pool/base/app-packages/app-package-picker.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class AppPackagePickerComponent implements ControlValueAccessor, Validato
6868
};
6969

7070
// subscribe to the application data proxy
71-
this._subscriptions.push(this._data.items.subscribe((applications) => {
71+
this._data.items.subscribe((applications) => {
7272
this._applicationMap = {};
7373
if (applications.size > 0) {
7474
this._mapApplicationPackages(applications);
@@ -83,7 +83,7 @@ export class AppPackagePickerComponent implements ControlValueAccessor, Validato
8383
index++;
8484
});
8585
}
86-
}));
86+
});
8787

8888
// subscribe to the form change events
8989
this._subscriptions.push(this.items.valueChanges.subscribe((references: PackageReference[]) => {
@@ -114,6 +114,7 @@ export class AppPackagePickerComponent implements ControlValueAccessor, Validato
114114
}
115115

116116
public ngOnDestroy() {
117+
this._data.dispose();
117118
this._subscriptions.forEach(x => x.unsubscribe());
118119
}
119120

app/services/core/data-cache.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ export class DataCacheTracker {
2323
}
2424
}
2525

26+
public static disposeAll() {
27+
for (const cache of ObjectUtils.values(this._caches)) {
28+
cache.clear();
29+
this.unregisterCache(cache);
30+
}
31+
}
32+
2633
private static _caches: { [key: string]: DataCache<any> } = {};
2734
}
2835

@@ -70,7 +77,6 @@ export class DataCache<T> {
7077
public dispose() {
7178
this.clear();
7279
DataCacheTracker.unregisterCache(this);
73-
// TODO implement dispose
7480
}
7581

7682
/**

app/services/core/data/generic-view.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ export abstract class GenericView<TEntity, TParams, TOptions extends ProxyOption
9090
});
9191

9292
this.deleted = this._deleted.asObservable();
93+
this.init();
94+
}
95+
96+
public init() {
97+
// Nothing to do. Used in test for stub;
9398
}
9499

95100
public set params(params: TParams) {

0 commit comments

Comments
 (0)