[PonyORM-list] Deletion of an object taking a lot of memory?

Alexander Kozlovsky alexander.kozlovsky at gmail.com
Mon Feb 15 16:48:33 UTC 2016


Hi Matthew,

When somebody performs `x.delete()`, Pony loads all dependent objects to
memory and call delete method recursively on them. This is necessary,
because potentially any dependent object can have `before_delete` and
`after_delete` hooks.

I think we can do the following improvement here: if we a sure that
deleting an object will not invoke any user-defined hooks, we can delegate
the deletion to the database. In order to do this, we need to add ON DELETE
CASCADE to all foreign keys which Pony defines. This approach has one
potential drawback: if any dependent object was already loaded into session
cache, Pony will not know that the object was already deleted in the
database and will not invalidate cache record.

In order to avoid cache inconsistencies, we can delete objects via Python,
but don't load any columns of dependent objects except primary key values.
This way we can potentially reduce memory consumption.


Regards,
Alexander


On Sat, Feb 13, 2016 at 4:22 PM, Matthew Bell <matthewrobertbell at gmail.com>
wrote:

> Hi,
>
> I have measured a script doing:
>   x = X.get(1)
>   x.delete()
>
> using 5.7GB ram. the object has a lot of related object, through
> one-to-many relations. Is there a way to stop all of this memory being used?
>
> Thanks
>
> --
> Regards,
>
> Matthew Bell
>
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
> /ponyorm-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20160215/0dce9307/attachment.html>


More information about the ponyorm-list mailing list