fixes for memory leaks and multiple subscriptions (#3456)

* fix content action memory leaks

* memory leak fixes for demo shell
This commit is contained in:
Denys Vuika
2018-06-07 23:24:51 +01:00
committed by Eugenio Romano
parent beeb7bd369
commit 346dff436d
5 changed files with 95 additions and 59 deletions

View File

@@ -15,13 +15,14 @@
* limitations under the License.
*/
import { Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core';
import { Component, Input, OnChanges, OnInit, ViewChild, OnDestroy } from '@angular/core';
import { ProcessInstance, ProcessService ,
ProcessAttachmentListComponent, ProcessUploadService } from '@alfresco/adf-process-services';
import { UploadService } from '@alfresco/adf-core';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { AppConfigService } from '@alfresco/adf-core';
import { PreviewService } from '../../services/preview.service';
import { Subscription } from 'rxjs/Subscription';
export function processUploadServiceFactory(api: AlfrescoApiService, config: AppConfigService) {
return new ProcessUploadService(api, config);
@@ -40,7 +41,7 @@ export function processUploadServiceFactory(api: AlfrescoApiService, config: App
]
})
export class ProcessAttachmentsComponent implements OnInit, OnChanges {
export class ProcessAttachmentsComponent implements OnInit, OnChanges, OnDestroy {
@ViewChild('processAttachList')
processAttachList: ProcessAttachmentListComponent;
@@ -50,6 +51,8 @@ export class ProcessAttachmentsComponent implements OnInit, OnChanges {
processInstance: ProcessInstance;
private subscriptions: Subscription[] = [];
constructor(
private uploadService: UploadService,
private processService: ProcessService,
@@ -57,7 +60,11 @@ export class ProcessAttachmentsComponent implements OnInit, OnChanges {
) {}
ngOnInit() {
this.uploadService.fileUploadComplete.subscribe(value => this.onFileUploadComplete(value.data));
this.subscriptions.push(
this.uploadService.fileUploadComplete.subscribe(
value => this.onFileUploadComplete(value.data)
)
);
}
ngOnChanges() {
@@ -69,6 +76,11 @@ export class ProcessAttachmentsComponent implements OnInit, OnChanges {
}
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => subscription.unsubscribe());
this.subscriptions = [];
}
onFileUploadComplete(content: any) {
this.processAttachList.add(content);
}

View File

@@ -137,7 +137,6 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
taskFilter: FilterRepresentationModel;
report: any;
processFilter: UserProcessInstanceFilterRepresentation;
sub: Subscription;
blobFile: any;
flag = true;
@@ -151,6 +150,8 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
new DemoFieldValidator()
];
private subscriptions: Subscription[] = [];
constructor(private elementRef: ElementRef,
private route: ActivatedRoute,
private router: Router,
@@ -172,27 +173,26 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
// Uncomment this line to map 'custom_stencil_01' to local editor component
formRenderingService.setComponentTypeResolver('custom_stencil_01', () => CustomStencil01, true);
formService.formLoaded.subscribe((e: FormEvent) => {
this.logService.log(`Form loaded: ${e.form.id}`);
});
formService.formFieldValueChanged.subscribe((e: FormFieldEvent) => {
this.logService.log(`Field value changed. Form: ${e.form.id}, Field: ${e.field.id}, Value: ${e.field.value}`);
});
this.preferenceService.select(UserPreferenceValues.PaginationSize).subscribe((pageSize) => {
this.paginationPageSize = pageSize;
});
formService.validateDynamicTableRow.subscribe(
(validateDynamicTableRowEvent: ValidateDynamicTableRowEvent) => {
const row: DynamicTableRow = validateDynamicTableRowEvent.row;
if (row && row.value && row.value.name === 'admin') {
validateDynamicTableRowEvent.summary.isValid = false;
validateDynamicTableRowEvent.summary.message = 'Sorry, wrong value. You cannot use "admin".';
validateDynamicTableRowEvent.preventDefault();
this.subscriptions.push(
formService.formLoaded.subscribe((e: FormEvent) => {
this.logService.log(`Form loaded: ${e.form.id}`);
}),
formService.formFieldValueChanged.subscribe((e: FormFieldEvent) => {
this.logService.log(`Field value changed. Form: ${e.form.id}, Field: ${e.field.id}, Value: ${e.field.value}`);
}),
this.preferenceService.select(UserPreferenceValues.PaginationSize).subscribe((pageSize) => {
this.paginationPageSize = pageSize;
}),
formService.validateDynamicTableRow.subscribe(
(validateDynamicTableRowEvent: ValidateDynamicTableRowEvent) => {
const row: DynamicTableRow = validateDynamicTableRowEvent.row;
if (row && row.value && row.value.name === 'admin') {
validateDynamicTableRowEvent.summary.isValid = false;
validateDynamicTableRowEvent.summary.message = 'Sorry, wrong value. You cannot use "admin".';
validateDynamicTableRowEvent.preventDefault();
}
}
}
)
);
// Uncomment this block to see form event handling in action
@@ -208,7 +208,7 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
if (this.router.url.includes('processes')) {
this.activeTab = this.tabs.processes;
}
this.sub = this.route.params.subscribe(params => {
this.route.params.subscribe(params => {
const applicationId = params['appId'];
this.filterSelected = params['filterId'] ? { id: +params['filterId'] } : { index: 0 };
@@ -227,7 +227,8 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
}
ngOnDestroy() {
this.sub.unsubscribe();
this.subscriptions.forEach(subscription => subscription.unsubscribe());
this.subscriptions = [];
}
onTaskFilterClick(filter: FilterRepresentationModel): void {

View File

@@ -15,10 +15,11 @@
* limitations under the License.
*/
import { Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core';
import { Component, Input, OnChanges, OnInit, ViewChild, OnDestroy } from '@angular/core';
import { TaskListService, TaskAttachmentListComponent, TaskDetailsModel, TaskUploadService } from '@alfresco/adf-process-services';
import { UploadService, AlfrescoApiService, AppConfigService } from '@alfresco/adf-core';
import { PreviewService } from '../../services/preview.service';
import { Subscription } from 'rxjs/Subscription';
export function taskUploadServiceFactory(api: AlfrescoApiService, config: AppConfigService) {
return new TaskUploadService(api, config);
@@ -37,7 +38,7 @@ export function taskUploadServiceFactory(api: AlfrescoApiService, config: AppCon
]
})
export class TaskAttachmentsComponent implements OnInit, OnChanges {
export class TaskAttachmentsComponent implements OnInit, OnChanges, OnDestroy {
@ViewChild('taskAttachList')
taskAttachList: TaskAttachmentListComponent;
@@ -47,13 +48,19 @@ export class TaskAttachmentsComponent implements OnInit, OnChanges {
taskDetails: any;
private subscriptions: Subscription[] = [];
constructor(
private uploadService: UploadService,
private activitiTaskList: TaskListService,
private preview: PreviewService) {}
ngOnInit() {
this.uploadService.fileUploadComplete.subscribe(value => this.onFileUploadComplete(value.data));
this.subscriptions.push(
this.uploadService.fileUploadComplete.subscribe(
value => this.onFileUploadComplete(value.data)
)
);
}
ngOnChanges() {
@@ -65,6 +72,11 @@ export class TaskAttachmentsComponent implements OnInit, OnChanges {
}
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => subscription.unsubscribe());
this.subscriptions = [];
}
onFileUploadComplete(content: any) {
this.taskAttachList.add(content);
}