Make WordPress Core

Opened 12 years ago

Closed 9 years ago

#21672 closed defect (bug) (worksforme)

Custom menu memory problem

Reported by: pavelevap's profile pavelevap Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.1
Component: Menus Keywords:
Focuses: Cc:

Description

I found some strange memory problem related to updating custom menu. One website is using about 22 MB from 128 available (memory_limit). But when trying to update custom menu, there is error related to unsufficient memory.

This custom menu has about 100 items, I also tried to export it to my PC and testing memory uasge. There are some strange results...

In file wp-admin/nav-menus.php there is following line:

$menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args );

When I set memory checks before and after this line, then there are following results on my testing environment, for example:

Before: 25.28 MB
After: 25.29 MB

I added also some checks directly into wp_update_nav_menu_item() function and there are some small peaks (about 1 MB). But in the end (after this function) everything is somehow reset and memory usage is as low as in the beginning.

But when I test it with affected hosting, there are following results:

Before: 26.59 MB
After: 27.77 MB

So everytime wp_update_nav_menu_item() is running, 1 MB more is needed on this server and there is no reset. And because it is foreach cycle and menu has more than 100 items, then more then 128 MB is needed.

Same conditions, but one server needs more than 128 MB memory_limit and my local environment works well with 32 MB. There is no other problem with this hosting, everything works, no special server settings. Any ideas?

Change History (8)

#1 @wonderboymusic
12 years ago

The culprit here is probably clean_post_cache() - which is being addressed in WP_Post #21309

#2 @pavelevap
12 years ago

I also suspected WP cache, but how can be influenced by server (hosting) settings? My local environment is almost the same and everything works well...

#3 @DrewAPicture
12 years ago

  • Cc xoodrew@… added

#4 follow-up: @markoheijnen
12 years ago

I did notice today that the action "clean_post_cache" is getting fired on non existing posts too. This happens when I remove a menu item. Most likely it's getting called more then ones but I didn't looked into it.

#5 in reply to: ↑ 4 @nacin
12 years ago

Replying to markoheijnen:

I did notice today that the action "clean_post_cache" is getting fired on non existing posts too. This happens when I remove a menu item. Most likely it's getting called more then ones but I didn't looked into it.

That's by design — once the post is deleted, it needs to be removed from the cache. That's why clean_post_cache() takes a full object, rather than an ID, as it can't reliably perform a lookup as the post may be gone.

#6 @pavelevap
12 years ago

Observed problem disappeared somehow. My friend published some posts and pages and updated some plugins (we tested without them) and problem has gone, memory_limit is stable now. I am really not sure how it was caused and I could not reproduce it on localhost with exported menu. There were about 100 menu items (mostly pages), maybe it could be some hosting settings (I checked them and there was nothing special). Sorry, I could not reproduce it...

#7 @chriscct7
9 years ago

  • Keywords needs-patch added

#8 @ocean90
9 years ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

See comment:6.

Note: See TracTickets for help on using tickets.