Skip to content

Commit 42203ad

Browse files
committed
feat: 增加 revokeObjectURL 防止内存泄漏
1 parent 4d4faab commit 42203ad

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ export async function setData(id, data) {
4747
return;
4848
}
4949

50-
const { options, objectUrl } = pdf;
51-
if (objectUrl) {
52-
URL.revokeObjectURL(objectUrl);
53-
}
50+
const objectUrl = createObjectURLFromByte(data);
51+
pdf.objectUrl = objectUrl;
5452

55-
options.url = createObjectURLFromByte(data);
53+
const { options } = pdf;
54+
options.url = objectUrl;
5655
options.data = null;
57-
pdf.objectUrl = options.url;
5856
await loadPdf(pdf);
5957
}
6058

@@ -187,7 +185,11 @@ const loadPdf = async pdf => {
187185
}
188186

189187
const disposePdf = pdf => {
190-
const { el, observer, loadingTask } = pdf;
188+
const { el, observer, loadingTask, objectUrl } = pdf;
189+
if (objectUrl) {
190+
URL.revokeObjectURL(objectUrl);
191+
}
192+
191193
if (observer) {
192194
observer.disconnect();
193195
}

0 commit comments

Comments
 (0)