随着更多模态的添加,模态内存泄漏

时间:2017-11-30 15:26:41

标签: ngx-bootstrap ngx-bootstrap-modal

我正在大量使用ngx-bootstrap模式开发Angular 4应用程序。我目前正在使用模板+ modalService方式打开模态。在单击事件期间,此行代码称为:

@ViewChild() worklistTemplate;
// ...
this.modalRef = this.modalService.show(this.worklistTemplate, this.config);

工作清单模板如下所示:

<ng-template #worklistTemplate>
  <app-action-view
    [leftButtons]="leftButtons"
    [labelHeader]="modalHeader"
    [labelIcon]="modalIcon"
    [modalRef]="modalRef">
    <div class="row modal-info-panel">
      <div class="col-xs-4 modal-user-info">
        <fa name="mars" class="gender-icon"></fa>
        <div class="field-panel">
          <input type="text"
            [ngModel]="rowInfo.lastName"
            [ngClass]="{ 'modal-editable-field': modalFieldsEditable }"
            [disabled]="!modalFieldsEditable">
          <input type="text"
            [ngModel]="rowInfo.firstName"
            [ngClass]="{ 'modal-editable-field': modalFieldsEditable }"
            [disabled]="!modalFieldsEditable">
          <div>
            <label for="modal-mrn">MRN --</label>
            <input id="modal-mrn" type="text"
              [ngModel]="rowInfo.mrn"
              [ngClass]="{ 'modal-editable-field': modalFieldsEditable }"
              [disabled]="!modalFieldsEditable">
          </div>
          <div>
            <label for="modal-dob">DOB --</label>
            <input id="modal-dob" type="text"
              [ngModel]="rowInfo.birthDate"
              [ngClass]="{ 'modal-editable-field': modalFieldsEditable }"
              [disabled]="!modalFieldsEditable">
          </div>
          <div class="edit-panel">
            <fa *ngIf=modalFieldsEditable class="worklist-edit-buttons green-hover link" name="floppy-o" tooltip="Save" (click)=saveChanges()></fa>
            <fa *ngIf=modalFieldsEditable class="worklist-edit-buttons red-hover link" name="times" tooltip="Cancel" (click)=toggleModalFields()></fa>
          </div>
        </div>
      </div>
      <div class="col-xs-8 modal-id-info">
        Associated ID
        <div class="full-width">
          <div class="row" *ngFor="let i of rowInfo.associatedIDs">
            <div class="col-xs-6 cell">{{i.id}}</div><div class="col-xs-6 cell">{{i.source}}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="row" id="modal-table">
      <app-table-view
            [columns]="objDetailsCols"
            [tableData]="objDetailsData"
            [expandTemplate]="rowImageContainer"
            [expandColStyle]="expandColStyle">
      </app-table-view>
    </div>
    <div *ngIf="resolvePanelVisible" class="resolve-panel"
      [@slideRight]>
      <div class="resolve-label">
        <fa class="lt-icon" name="wrench"></fa>
        Resolve QA Issue
      </div>
      <div class="resolve-body">
        Hello, World!
      </div>
      <div class="resolve-footer">
        <a>Validate</a>
        <a>Resolve</a>
        <a>Reload</a>
        <a (click)="toggleResolvePanel()">Close</a>
      </div>
    </div>
  </app-action-view>
</ng-template>

可以通过单击模态边界外部来关闭模态,或者在ActionViewComponent中有一个调用modalRef.hide()的按钮。

随着越来越多的模态被打开,内存使用量急剧增加。事实上,如果我打开模式大约5次,应用程序变得迟钝,几乎无法使用。如果TableViewComponent中有很多行,这一点尤其明显。

我使用模态的方式是否存在问题,或者这是与ngx-bootstrap模式相关的问题?或者,与浏览器有关的问题是不可避免的?我正在开发Chrome 62。

我已经确认在模式内的TableViewComponent上永远不会调用onDestroy。如果我导航到不同的页面组件,甚至不会调用它,尽管另一个表(不在模板中)在从页面导航时调用onDestroy。

任何反馈都非常受欢迎 - 我在这方面已经被困了太久了。

1 个答案:

答案 0 :(得分:1)

遗憾的是,这是ngx-bootstrap的一个问题。我创建了一个拉取请求(https://github.com/valor-software/ngx-bootstrap/pull/3179),因此只要我的PR合并并发布了新版本,就会修复此问题。

相关问题