The issue is related to the new way of URL rewrites generator in Magento2. In Magento2, URL rewrites are generated (in url_rewrite table) when user save the category. If you have a complex category structure and assign a category as child of multiple parents or using categories across different store_views , it tries to generate the URL for all combinations and hence get out of memory.
Here are some links I'd recommend you to go through so you might found a solution for your problem.
https://github.com/magento/magento2/issues/9706
https://github.com/magento/magento2/issues/10242
This is not a solution but a workaround.
I had also face the same issue with after migrating a huge Magento1 site. Here is the hack down there that is not a solution but it can confirm the issue for you. Update the following core file for instance and then try to update the category name.
M2\vendor\magento\module-catalog-url-rewrite\Observer\CategoryProcessUrlRewriteSavingObserver.php
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogUrlRewrite\Observer;
use Magento\Catalog\Model\Category;
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
use Magento\UrlRewrite\Model\UrlPersistInterface;
use Magento\Framework\Event\ObserverInterface;
class CategoryProcessUrlRewriteSavingObserver implements ObserverInterface
{
/** @var CategoryUrlRewriteGenerator */
protected $categoryUrlRewriteGenerator;
/** @var UrlPersistInterface */
protected $urlPersist;
/** @var UrlRewriteHandler */
protected $urlRewriteHandler;
/**
* @param CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator
* @param UrlPersistInterface $urlPersist
* @param UrlRewriteHandler $urlRewriteHandler
*/
public function __construct(
CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator,
UrlPersistInterface $urlPersist,
UrlRewriteHandler $urlRewriteHandler
) {
$this->categoryUrlRewriteGenerator = $categoryUrlRewriteGenerator;
$this->urlPersist = $urlPersist;
$this->urlRewriteHandler = $urlPersist;
}
/**
* Generate urls for UrlRewrite and save it in storage
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var Category $category */
/* $category = $observer->getEvent()->getCategory();
if ($category->getParentId() == Category::TREE_ROOT_ID) {
return;
}
if ($category->dataHasChangedFor('url_key')
|| $category->dataHasChangedFor('is_anchor')
|| $category->getIsChangedProductList()
) {
$urlRewrites = array_merge(
$this->categoryUrlRewriteGenerator->generate($category),
$this->urlRewriteHandler->generateProductUrlRewrites($category)
);
$this->urlPersist->replace($urlRewrites);
} */
}
}