Problem/Motivation

Repro case:

  1. Copy links.html.twig to your theme
  2. Add {{ dump(links) }} into the file
 * @see template_preprocess_links()
 */
#}
{{ dump(links) }}
{% if links -%}
  {%- if heading -%}
    {%- if heading.level -%}
      <{{ heading.level }}{{ heading.attributes }}>{{ heading.text }}
    {%- else -%}
      

{{ heading.text }}

{%- endif -%}
[09-Jan-2016 12:04:48 Europe/Berlin] PHP Fatal error:  Out of memory (allocated 312475648) (tried to allocate 294125568 bytes) in drupal8\vendor\twig\twig\lib\Twig\Extension\Debug.php on line 56

[09-Jan-2016 12:10:43 Europe/Berlin] PHP Fatal error:  Out of memory (allocated 415236096) (tried to allocate 398458880 bytes) in drupal8\vendor\twig\twig\lib\Twig\Extension\Debug.php on line 56

[09-Jan-2016 12:16:19 Europe/Berlin] PHP Fatal error:  Out of memory (allocated 415236096) (tried to allocate 398196736 bytes) in drupal8\vendor\twig\twig\lib\Twig\Extension\Debug.php on line 56

[09-Jan-2016 13:02:59 Europe/Berlin] PHP Fatal error:  Out of memory (allocated 159383552) (tried to allocate 142344192 bytes) in drupal8\vendor\twig\twig\lib\Twig\Extension\Debug.php on line 56

[09-Jan-2016 13:08:29 Europe/Berlin] PHP Fatal error:  Out of memory (allocated 414711808) (tried to allocate 398458880 bytes) in drupal8\vendor\twig\twig\lib\Twig\Extension\Debug.php on line 56

My development server memory limit per php.ini is memory_limit=2048M what should cover really everything.

Proposed resolution

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

hass created an issue. See original summary.

hass’s picture

Issue summary: View changes
hass’s picture

Issue summary: View changes
Cottser’s picture

Status: Active » Closed (works as designed)

Dump is just var_dump so yeah it will run out of memory. I recommend kint from devel instead.

hass’s picture

Status: Closed (works as designed) » Active

That's a joke, isn't it? A simple links array makes an out of memory? Why? Why exists such features that cannot dump a single string? I tried it in other places with strings, too.

Kint cannot used inside a twig template as I know. Using kint also causes troubles as the output is cached.

dawehner’s picture

@hass
Please be nice to people, as you want the same from them. Your assumption that kint() is not available from within templates is wrong, see http://cgit.drupalcode.org/devel/tree/kint/src/Twig/KintExtension.php.

@Cottser
What about also replacing dump() from within the kint module, just to have both things available?

hass’s picture

The question was why dump in twig is not working and causing out of memory. Pointing me to kint does not fix this bug. Closing this valid case also does not.

dawehner’s picture

@hass
I won't answer your comment, due to your niceness.

hass’s picture

No problem, i'm nice.

Cottser’s picture

@hass if you want dump "fixed" (as I said it's just var_dump so not sure what you're going to change) you're going to have to file an upstream bug with Twig.

@dawehner not sure what you mean by replacing dump - make dump do kint when kint is installed?

dawehner’s picture

@dawehner not sure what you mean by replacing dump - make dump do kint when kint is installed?

Exactly.

swentel’s picture

xjm’s picture

Priority: Major » Normal

@webchick, @alexpott, @catch, @effulgentsia and I agreed that this is a normal priority issue.

Cottser’s picture

Status: Active » Postponed (maintainer needs more info)

I'd rather not magically change dump() to kint() when kint is installed, it feels too magical. What if you have kint installed but still want to use dump() for some reason?

IMO this should still be closed won't fix like I said in #4. This is not a Drupal issue, it's a PHP issue if anything, not even Twig. I could be wrong but I'm fairly sure the exact same thing would happen if you had the same object(s) in PHPTemplate and ran var_dump() on them.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

FiNeX’s picture

Anyway, even kint() returns the memory exhausted error when I've tried to debug the ECK twig template.

aliyakhan’s picture

yes, even kint() does same. Any update on it?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

There has been documentation for this in the Theming guide.
https://www.drupal.org/docs/8/theming/twig/discovering-and-inspecting-va...

Feel free to re-open if you have a solution to deal with this, closing to triage. #14 needs addressing

hass’s picture

Status: Closed (won't fix) » Active

It is still not clear how a few links can require 2gb+ of memory in a dump. That is not realistic.

dawehner’s picture

The best "workaround" for that kind of problem is to simple use the right tool for the job aka. a debugger.

hass’s picture

If I'd like to dump a few variables this is the debugger and this should work and not crash PHP. This is a feature of Twig and it seems to be broken in Drupal.

swentel’s picture

@hass no - this isn't Drupal specific. Symfony has the same problem as well depending on what you dump. Ladybug is what most symfony people advise to use. There's even a Drupal extension at https://www.drupal.org/project/ld - although I haven't tested it yet.

dawehner’s picture

yi_jiang’s picture

I got the same issue, as a developer just wish to template a view tpl, it's very expensive to use kint or dump. site went to down after I try to dump the variables. I am not the frontend dev, so how is the fast way to see the variables

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

peezy’s picture

I believe the memory limit issue is related to recursions ( see https://www.drupal.org/node/2277303#comment-11168509 ). Krumo used to just print an infinity sign and move along; however, Kint goes deeper into arrays/objects which eventually maxes out the PHP memory limit.

The good news is that there is a request to add a UI to Kint to set the max-levels (see https://www.drupal.org/node/2405179 ). Until then a good workaround is to make sure your memory level is at 1024M and patch ~line 78 of /modules/contrib/devel/kint/kint/config.default.php so that it says $_kintSettings['maxLevels'] = 5;. The default level is 7.

yi_jiang’s picture

thx Peezy, it good to know.

hass’s picture

@keezy: This is about Twig dump, not Krumo or Kint.