You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a file is written, the size of the file is leaked in memory.
Expected Behavior
There should be no memory leaks when writing a file.
Code Reproduction
I can provide the following code to reproduce the issue.
import{Component}from'@angular/core';import{Directory,Encoding,Filesystem}from'@capacitor/filesystem';import{IonButton}from'@ionic/angular/standalone';
@Component({selector: 'app-root',template: `<ion-button (click)="repro()">Repro</ion-button>`,standalone: true,imports: [IonButton],})exportclassAppComponent{asyncrepro(){constchars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';constrandomIndex=Math.floor(Math.random()*chars.length);constchar=chars[randomIndex];// Note that the leak only occurs when the data differs.constdata=char.repeat(1024*1024*10);// 10mb of datareturnFilesystem.writeFile({directory: Directory.External,path: 'test.txt',encoding: Encoding.UTF8,// Does not happen with base64 encoding.
data
})}}
Open the dev tools and click on the repro button.
Notice the memory is climbing up every time even if we run a GC.
Other Technical Details
I'm using Angular v18.
The leak only occurs when the data differs between writes & the encoding is not base64 (utf8).
Additional Context
None
The text was updated successfully, but these errors were encountered:
It's not a capacitor issue.
Removing the data from the options after writeFile solves the issue:
import{Component}from'@angular/core';import{Directory,Encoding,Filesystem}from'@capacitor/filesystem';import{IonButton}from'@ionic/angular/standalone';
@Component({selector: 'app-root',template: `<ion-button (click)="repro()">Repro</ion-button>`,standalone: true,imports: [IonButton],})exportclassAppComponent{repro(){constchars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';constrandomIndex=Math.floor(Math.random()*chars.length);constchar=chars[randomIndex];// Note that the leak only occurs when the data differs.constdata=char.repeat(1024*1024*10);// 10mb of dataconstoptions={directory: Directory.External,path: 'test.txt',
data,encoding: Encoding.UTF8};returnFilesystem.writeFile(options).finally(()=>(options.dataasany)=null);}}
Bug Report
Plugin(s)
@capacitor/filesystem version 7.0.0
Capacitor Version
Platform(s)
Android for sure. I'm unable to test for iOS.
Current Behavior
When a file is written, the size of the file is leaked in memory.
Expected Behavior
There should be no memory leaks when writing a file.
Code Reproduction
I can provide the following code to reproduce the issue.
Open the dev tools and click on the repro button.

Notice the memory is climbing up every time even if we run a GC.
Other Technical Details
I'm using Angular v18.
The leak only occurs when the data differs between writes & the encoding is not base64 (utf8).
Additional Context
None
The text was updated successfully, but these errors were encountered: