Git Product home page Git Product logo

Comments (16)

jdecool avatar jdecool commented on September 26, 2024 2

No need to investigate IMO

I've made other tests.

Memory leak occurred in 1.38.0 and 1.38.1 but seems to be fixed in 1.38.2

We can close this issue.

Thanks @nikophil & @kbond

Really appreciate your work on this library.

from foundry.

kbond avatar kbond commented on September 26, 2024 1

I don’t use a Factory to construct this object, I create an instance manually.

But it's still wrapped in a proxy? This is the part I don't understand - I don't know how this can happen.

Anyway, we're in a big aside here from the original purpose of this issue - feel free to open a second issue to discuss this proxy problem further - it is legit.

from foundry.

jdecool avatar jdecool commented on September 26, 2024 1

still eager to understand what happened here.

Hard to find the time to correctly investigate this issue in depth.

Or at least, this would be nice to know if the memory leak does not occur in v2

Just update the project to v2 and there's no memory leak anymore.

from foundry.

nikophil avatar nikophil commented on September 26, 2024

Hi @jdecool πŸ‘‹

that's... surprising! πŸ˜…

I did not notice this problem in any project where I've tested this whole migration path πŸ€”

I track the source of the memory leak, I will update this issue.

OK, thanks, let's tackle this

from foundry.

kbond avatar kbond commented on September 26, 2024

Could it be related to all the deprecations being called? That's probably too large a spike for this to be the culprit.

from foundry.

jdecool avatar jdecool commented on September 26, 2024

Could it be related to all the deprecations being called? That's probably too large a spike for this to be the culprit.

I don't think that could explain the spike especially as I run the Rector Rule to fix them.

I track the source of the memory leak, I will update this issue.

I'm sorry for the delay of the investigation but I don't have much time to do this.

So I tried to update the project to Foundry 2 to see if it fix this issue.

But I have a problem.

I've a factory like this:

final class MyEntityFactory extends PersistentProxyObjectFactory
{
    protected function defaults(): array|callable
    {
        return [
            // ...
            'telephoneMobile' => self::faker()->optional(0.8)->mobileNumber(),
            'telephoneAutre' => self::faker()->optional(0.3)->phoneNumber(),
        ];
    }

    protected function initialize(): static
    {
        // see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
        return $this
            ->beforeInstantiate(function (array $attributes): array {
                // ...

                // Transform string into PhoneNumber object
                $attributes['telephoneMobile'] = $this->parsePhoneNumber($attributes['telephoneMobile']);
                $attributes['telephoneAutre'] = $this->parsePhoneNumber($attributes['telephoneAutre']);

                return $attributes;
            })
        ;
    }
}

The parsePhoneNumber return an instance of libphonenumber\PhoneNumber.

In foundry 2, this object is now wrap in a proxy using the Symfony\Component\VarExporter\Symfony\Component\VarExporter. The problem that the PhoneNumber class already define a public function unserialize($serialized) that is not compatible with the Symfony trait (public function __unserialize(array $data): void).

So it will throw an exception.

I don't know how to tell Foundry to not use a proxy for this object.

from foundry.

jdecool avatar jdecool commented on September 26, 2024

I'm sorry for the delay of the investigation but I don't have much time to do this.

Currently I've just seen that there is a lot of strings that are staying in memory.

I'm looking for which part of the code keep those strings in memory.

from foundry.

kbond avatar kbond commented on September 26, 2024

I don't know how to tell Foundry to not use a proxy for this object.

PhoneNumber is wrapped in a proxy? Is it an entity?

from foundry.

jdecool avatar jdecool commented on September 26, 2024

Yes from an external package

from foundry.

kbond avatar kbond commented on September 26, 2024

And you created a factory class for it? In foundry 2 you can have a factory extend PersistentObjectFactory (instead of PersistentProxyObjectFactory) and created objects won't be proxied.

FYI, we are working on some proxy improvements that should solve this issue soon.

from foundry.

pmontoya avatar pmontoya commented on September 26, 2024

I use the same library and I have the same issue. It's not a factory for this class. This class is used for a property of an entity.
The library declare the function __unserialize($data) and LazyProxyTrait declare the function __unserialize(array $data): void

from foundry.

kbond avatar kbond commented on September 26, 2024

Ok, I'm still not sure how PhoneNumber is being proxied. @jdecool, can you share what your parsePhoneNumber looks like?

from foundry.

jdecool avatar jdecool commented on September 26, 2024

Sorry. Just realise my issue is incomplete.

Je PhoneNumber come from https://packagist.org/packages/giggsey/libphonenumber-for-php and I use https://packagist.org/packages/odolbeau/phone-number-bundle for the Symfony integration.

I don’t use a Factory to construct this object, I create an instance manually.

from foundry.

jdecool avatar jdecool commented on September 26, 2024

feel free to open a second issue to discuss this proxy problem further - it is legit.

βœ…

#639

from foundry.

nikophil avatar nikophil commented on September 26, 2024

still eager to understand what happened here. Or at least, this would be nice to know if the memory leak does not occur in v2

from foundry.

nikophil avatar nikophil commented on September 26, 2024

ok, that's nice! No need to investigate IMO

from foundry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.