primeng icon indicating copy to clipboard operation
primeng copied to clipboard

DataTable component: memory leak

Open spzSource opened this issue 10 years ago • 6 comments

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:

  1. Open View_1
  2. Navigate to View_2
  3. 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:

screen shot 2016-06-16 at 00 40 52

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!

spzSource avatar Jun 15 '16 22:06 spzSource

Thanks we'll review. May I ask how do you check for the memory usage in your case?

cagataycivici avatar Jun 19 '16 08:06 cagataycivici

@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.

spzSource avatar Jun 19 '16 11:06 spzSource

Thank you, we're investigating.

cagataycivici avatar Jun 22 '16 18:06 cagataycivici

Maybe the problem is that the "implements OnDestroy" is missing in class declaration.

izll avatar Jun 23 '16 20:06 izll

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.

cagataycivici avatar Jul 23 '16 17:07 cagataycivici

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?

bencameron00 avatar Dec 05 '16 12:12 bencameron00