I launch & destroy iframe multiple times on single page. On click of "launch" button I create iframe as mentioned in below code snippet:
$('#container').html('<iframe id="iframeUniqueId" style="height:100%; width:100%;" src=""></iframe>');
let iframe = $('#container').find('iframe');
$(iframe).attr('src', 'https://..............');
On click of "destroy" button I destroy iframe as mentioned in below code snippet:
$("#iframeUniqueId").remove();
Now, the problem here is that the heap size in browser keeps on increasing continuously when I launch & destroy the iframe multiple times. Looks like memory is not getting released on destroying the iframe. Please refer screenshot of snapshots (which I took in Windows Chrome 101):
I have checked the this issue in multiple browsers like Windows10 chrome (v101), Windows10 firefox(v100), MAC safari(v15). Please note, in safari it seems that memory is not releasing at all on destroying an iframe and memory keeps on increasing by the time(on launching/destroying iframe multiple times), looks like garbage collection is not working at all.
I am unable to find any official references/documentation(best practice) on how to handle these memory leaks in case of an iframe. Is there any workaround I can apply here which can release memory on destroying an iframe.