Skip to content

SVGMobject and MathTex automatic caching issues #4327

@OliverStrait

Description

@OliverStrait

Description of bug / unexpected behavior

While testing a root of this conversation: #4321 of cumulation of memory usage even when User created Tex mobjects has been carbage collected.
I found that MathTex is creating an hidden mobjects that is copied and cached even when End User does not want to use a cache.

Observations:

  • Clear issue here is the automatic unlimited cache that will make copy of complex datastructures (Mobject). That will limit what you can do with Manim.
  • MathTex creates an additional SingleStringMathTex that does not inherit user stated flag. This is created at: MathTex._break_up_by_substrings() -> Tricky to fix because adding temp flag to object memory to pass the flag is not desired solution in any cases.
  • (OpenGl pipeline is holding reference to User faced mobject, small memory cumulation. Maybe this is actually cleared in normal pipeline logic.)

Solutions

  • Simplest way is to change default state of flag to False in SvgMobject
  • Limiting automatic cache size, but this code will add additional burden.
  • Removing whole dictionary caching:
    • Is automatic caching into RAM actually needed?
    • What I have observed, most times people just use something once and create other unique construct.
    • This kind of system is against mentality of 'not to solve all End User problems at once'. Is it that big burden to let User to copy their own Mobjects when needed?

Context

from manim.mobject.svg.svg_mobject import SVG_HASH_TO_MOB_MAP
tex = Tex(f"$\\text{{Test String }} {i} \\times \\sum_{{n=1}}^{{\\infty}} \\frac{{1}}{{n^2}} = \\frac{{\\pi^2}}{{6}}$", use_svg_cache = False)
len(SVG_HASH_TO_MOB_MAP) # should be zero, but is not

Patch solution

If memory usage may be a problem one can purge the cache manually just clearing it:

from manim.mobject.svg.svg_mobject import SVG_HASH_TO_MOB_MAP
SVG_HASH_TO_MOB_MAP.clear()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions