mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-04-10 07:14:04 +02:00
The purpose of PR 11844 was to reduce memory usage once fonts have been attached to the DOM, since the font-data can be quite large in many cases. Unfortunately the new `clearData` method added in PR 20197 doesn't actually remove *anything*, it just replaces the font-data with zeros which doesn't help when the underlying `ArrayBuffer` itself isn't modified. The method does include a commented-out `resize` call[1], but uncommenting that just breaks rendering completely. To address this regression, without having to make large or possibly complex changes, this patch simply changes the `clearData` method to replace the internal buffer/view with its contents *before* the font-data. While this does lead to a data copy, the size of this data is usually orders of magnitude smaller than the font-data that we're removing. --- [1] Slightly off-topic, but I don't think that patches should include commented-out code since there's a very real risk that those things never get found/fixed. At the very least such cases should be clearly marked with `// TODO: ...` comments, and should possibly also have an issue filed about fixing the TODO.