Project

General

Profile

Actions

Defect #44800

closed

Memory leak when rendering code blocks

Defect #44800: Memory leak when rendering code blocks

Added by Katsuya HIDAKA 10 days ago. Updated 5 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Text formatting
Target version:
Resolution:
Fixed
Affected version:

Description

CopypreScrubber, which adds a copy button to code blocks, leaks memory. It caches one Nokogiri wrapper node and passes it to wrap for every pre. Because that node belongs to another document, each rendered HTML document stays in memory after rendering. The cached node was added in r24360 (#43643).

The attached patch creates a new wrapper node for each code block instead of caching it, as #43801 did for the copy button. This fixes the leak.

Live HTML documents after GC (Ruby 4.0.7, Nokogiri 1.19.7). CommonMark and Textile gave the same results:

Renders Before the patch After the patch
500 501 1
1,000 1,001 1

Reproduction script

Details:

  • Node#wrap duplicates the cached node and moves the copy into the document being rendered. The Ruby object of the copy stays in the node cache of the cached node's document. That document lives as long as the scrubber, and the scrubbers are constants (SCRUBBERS), so every rendered document stays in memory.
  • The HTML output does not change. I checked pre at the top level and inside li, blockquote, td, p and details.
  • Negligible performance impact. In a local benchmark with 20 code blocks per render, the median render time changed by less than 0.2 ms (about 2.5 ms per render).
  • All tests pass.

This may be related to #44766.


Files


Related issues 1 (0 open — 1 closed)

Related to Redmine - Patch #43643: Align the Textile processing approach with CommonMark by using LoofahClosedMarius BĂLTEANUActions

Updated by Go MAEDA 9 days ago Actions #1

  • Related to Patch #43643: Align the Textile processing approach with CommonMark by using Loofah added

Updated by Go MAEDA 9 days ago Actions #2

  • Target version set to 7.0.4

Setting the target version to 7.0.4.

Updated by Go MAEDA 8 days ago Actions #3

  • Status changed from New to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the fix in r25494. Thank you.

Updated by Go MAEDA 5 days ago Actions #4

  • Status changed from Resolved to Closed

Merged the fix into 7.0-stable branch in r25501.

Actions

Also available in: PDF Atom