{"record":{"id":"27d190132e9b3817","repo":"Shopify/liquid","slug":"memory-limits-exceeded","errorCode":null,"errorMessage":"Memory limits exceeded","messagePattern":"Memory limits exceeded","errorType":"exception","errorClass":"Liquid::MemoryError","httpStatus":null,"severity":"error","filePath":"lib/liquid/resource_limits.rb","lineNumber":54,"sourceCode":"      raise_limits_reached if @assign_score_limit && @assign_score > @assign_score_limit\n      raise_limits_reached if @cumulative_assign_score_limit && @cumulative_assign_score > @cumulative_assign_score_limit\n    end\n\n    # update either render_length or assign_score based on whether or not the writes are captured\n    def increment_write_score(output)\n      if (last_captured = @last_capture_length)\n        captured = output.bytesize\n        increment = captured - last_captured\n        @last_capture_length = captured\n        increment_assign_score(increment)\n      elsif @render_length_limit && output.bytesize > @render_length_limit\n        raise_limits_reached\n      end\n    end\n\n    def raise_limits_reached\n      @reached_limit = true\n      raise MemoryError, \"Memory limits exceeded\"\n    end\n\n    def reached?\n      @reached_limit\n    end\n\n    def reset\n      @reached_limit = false\n      @last_capture_length = nil\n      @render_score = @assign_score = 0\n      raise_limits_reached if @cumulative_render_score_limit && @cumulative_render_score > @cumulative_render_score_limit\n      raise_limits_reached if @cumulative_assign_score_limit && @cumulative_assign_score > @cumulative_assign_score_limit\n    end\n\n    def with_capture\n      old_capture_length = @last_capture_length\n      begin\n        @last_capture_length = 0","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/resource_limits.rb#L36-L72","documentation":"Liquid::ResourceLimits raises Liquid::MemoryError via raise_limits_reached when a template exceeds configured resource limits (render length, allocation counts, variable or output sizes). It flags that the template consumed more resources than allowed and aborts rendering.","triggerScenarios":"Rendering a template whose output, variable sizes, or loop allocations exceed ResourceLimits (e.g. render_length_limit, render_score_limit, alloc_profiler budgets) set on Liquid::Template via resource_limits or a render call with limits.","commonSituations":"User-submitted or merchant themes with very large loops or huge string concatenations; rendering extremely large product/JSON dumps; lowering limits for sandboxed rendering and hitting them on legitimate templates.","solutions":["Raise the resource limits if they're too strict (template.resource_limits = { render_length_limit: ..., render_score_limit: ... })","Refactor the template to reduce output size (paginate loops, truncate strings)","Profile the template with resource limit tracking to find the offending construct and optimize it"],"exampleFix":"# before\ntemplate.render(assigns)\n# after\ntemplate.resource_limits = Liquid::ResourceLimits.new(render_length_limit: 500_000)\ntemplate.render(assigns)","handlingStrategy":"try-catch","validationCode":"limits = template.resource_limits\nraise unless limits # ensure limits configured sensibly for template complexity","typeGuard":null,"tryCatchPattern":"begin\n  template.render(assigns)\nrescue Liquid::MemoryError => e\n  Rails.logger.warn(\"Template exceeded resource limits: #{template_name}\")\n  render_fallback_or_paginated_view\nend","preventionTips":["Paginate large collections in templates","Set realistic resource_limits for your workload","Profile heavy templates with limit instrumentation","Truncate or cap large string outputs"],"tags":["liquid","template-engine","resource-limits","memory"],"backgroundTag":"resource-limit-exceeded","analyzedSha":"807d45a6b3d4568e64e86b375e3702df2c7c860c","analyzedAt":"2026-09-08T11:31:38.917Z","contentChangedAt":"2026-09-08T11:31:38.917Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}