Opened 12 years ago
Closed 9 years ago
#21672 closed defect (bug) (worksforme)
Custom menu memory problem
Reported by: | 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)
#2
@
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...
#4
follow-up:
↓ 5
@
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
@
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
@
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...
The culprit here is probably clean_post_cache() - which is being addressed in WP_Post #21309