1

I have created model file but when I'm going to inject additional class in the constructor I'm getting the error and page is not working.

public function __construct(
    \Magento\Framework\Model\Context $context,
    \Magento\Framework\Registry $registry,
    \Vendor\QueAnswer\Helper\Data $qaHelper,
    \Vendor\QueAnswer\Model\ResourceModel\QueAnswer $resource,
    \Vendor\QueAnswer\Model\ResourceModel\QueAnswer\Collection $resourceCollection = null,
    array $data = []
) {
    parent::__construct($context, $registry, $resource, $resourceCollection, $data);
    $this->qaHelper = $qaHelper;
}

protected function _construct()
{
    //parent::_construct();
    $this->_init(ResourceModel\QueAnswer::class);
}

Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 262144 bytes) in /var/www/html/m2site/vendor/magento/framework/ObjectManager/Factory/Compiled.php on line 150

Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 262144 bytes) in /var/www/html/m2site/vendor/magento/framework/Session/SessionManager.php on line 151

Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0

Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 262144 bytes) in /var/www/html/m2site/vendor/magento/framework/Session/SaveHandler.php on line 91

2 Answers 2

0

you should replace the code

\Vendor\QueAnswer\Model\ResourceModel\QueAnswer $resource,
\Vendor\QueAnswer\Model\ResourceModel\QueAnswer\Collection $resourceCollection = null,

with the code below

 \Magento\Framework\Model\ResourceModel\AbstractResource $resource,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection,

then

rm -rf generated
php bin/magento s:d:c

I think it will work.

1
  • Still not working.
    – m2dev
    Oct 10, 2022 at 9:39
0

You can increase the memory limit in your bin/magento command: php -d memory_limit=4G bin/magento.

Example: php -d memory_limit=4G bin/magento s:d:c

You are also able to increase the memory limit in many ways, check: https://magento.stackexchange.com/a/209993/39884

Btw, you should replace your __construct method with the following code:

public function __construct(
    \Magento\Framework\Model\Context $context,
    \Magento\Framework\Registry $registry,
    \Vendor\QueAnswer\Helper\Data $qaHelper,
    \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
    \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
    array $data = []
) {
    parent::__construct($context, $registry, $resource, $resourceCollection, $data);
    $this->qaHelper = $qaHelper;
}
4
  • I have also tried this but not working.
    – m2dev
    Oct 10, 2022 at 9:07
  • you have to remove generated folder then re-compile DI: rm -rf generated && bin/magento s:d:c, then check if it works or not.
    – Tu Van
    Oct 10, 2022 at 9:10
  • Not working. Still getting error Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/m2site/vendor/magento/framework/ObjectManager/Factory/Compiled.php on line 75
    – m2dev
    Oct 10, 2022 at 9:29
  • I've updated my answer, please check.
    – Tu Van
    Oct 10, 2022 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.