DataTable component: memory leak
It seems there is some issue with memory leak in DataTable component.
Below is a simple code using which it is possible to reproduce memory leak.
import { Component, OnInit, ViewEncapsulation } from "@angular/core";
import { DataTable, Column } from 'primeng/primeng';
@Component({
selector: 'config-keys',
template: require('./keys.component.html'),
styles: [
require('primeui/themes/omega/theme.css'),
require('primeui/primeui-ng-all.min.css')
],
encapsulation: ViewEncapsulation.None,
directives: [Column, DataTable]
})
export class ConfigKeysComponent implements OnInit {
configKeys: SimpleConfigKey[] = [];
public ngOnInit(): any {
for (let i = 0; i < 1000; i++) {
this.configKeys.push(<SimpleConfigKey>{id: i, name: `Name ${i}`});
}
}
}
export interface SimpleConfigKey {
id: number;
name: string;
}
<p-dataTable [value]="configKeys">
<p-column field="id" header="Id"></p-column>
<p-column field="name" header="Name"></p-column>
</p-dataTable>
Pre-requirements: Need at least two separate views/components (View_1 and View_2 (with DataTable component)) to be able to navigate between them.
Steps for reproduce:
- Open View_1
- Navigate to View_2
- Repeat points 1 and 2 about 20-30 times.
Actual result: Every time when user navigates to View_2, memory usage increases by 30-40 MiB and it looks like GC can't collect them. See attached image below:
Note: The same issue is reproduced on primeng site here http://www.primefaces.org/primeng/#/datatable
Hope this will help to fix potential problem. I am able to provide more info if it is required.
Cheers!
Thanks we'll review. May I ask how do you check for the memory usage in your case?
@cagataycivici I've checked through the Task manager in google chrome (Shift + Esc shortcut), which shows the memory usage for each of tabs (the screen above is from Google task manager). Also, I have performed memory profiling using developer console in Google Chrome.
Thank you, we're investigating.
Maybe the problem is that the "implements OnDestroy" is missing in class declaration.
This might be fixed in upcoming beta.11, please confirm after beta.11 is released, if not we'll reopen. Rx based subscription for column changes are now cleared at onDestroy which is likely to be the reason.
I am seeing the same issue when when using the DataGrid. This is being hooked up to an RX Observable. Is it possible that the DataGrid needs the same fix as you did to the DataTable?