Re: [Django] #35279: Memory Leak with `prefetch_related`

2024-03-07 Thread Django
#35279: Memory Leak with `prefetch_related`
-+-
 Reporter:  Ken Tong |Owner:  nobody
 Type:   |   Status:  closed
  Cleanup/optimization   |
Component:  Database layer   |  Version:  4.2
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:  memory leak  | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Mariusz Felisiak):

 * stage:  Accepted => Unreviewed

Comment:

 TIL
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e1c6e4bb5-e45c970f-60f4-4fee-98f1-cb49b6dc1803-00%40eu-central-1.amazonses.com.


Re: [Django] #35279: Memory Leak with `prefetch_related`

2024-03-07 Thread Django
#35279: Memory Leak with `prefetch_related`
-+-
 Reporter:  Ken Tong |Owner:  nobody
 Type:   |   Status:  closed
  Cleanup/optimization   |
Component:  Database layer   |  Version:  4.2
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:  memory leak  | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Ken Tong):

 * resolution:   => invalid
 * status:  new => closed

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e1c0b4cc1-82aa4ec9-bff3-4611-861b-3d2f423c6639-00%40eu-central-1.amazonses.com.


Re: [Django] #35279: Memory Leak with `prefetch_related`

2024-03-07 Thread Django
#35279: Memory Leak with `prefetch_related`
-+-
 Reporter:  Ken Tong |Owner:  nobody
 Type:   |   Status:  new
  Cleanup/optimization   |
Component:  Database layer   |  Version:  4.2
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  memory leak  | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Comment (by Ken Tong):

 Thank you for your detailed explanation, Antoine. I confirm that memory
 leak is a false alarm and I am sorry about it
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e1c0a593d-56865a2b-f604-4051-bb26-f16fd004a1bb-00%40eu-central-1.amazonses.com.


Re: [Django] #35279: Memory Leak with `prefetch_related`

2024-03-07 Thread Django
#35279: Memory Leak with `prefetch_related`
-+-
 Reporter:  Ken Tong |Owner:  nobody
 Type:   |   Status:  new
  Cleanup/optimization   |
Component:  Database layer   |  Version:  4.2
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  memory leak  | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Comment (by Antoine Humbert):

 The following code snippet shows the same result:

 {{{

 import gc


 class Parent:

 def __init__(self):
 self.cache = {}


 class Child:

 def __init__(self, parent):
 self.parent = parent



 def test():
 foo = Parent()
 bar = Child(parent=foo)
 foo.cache["bars"] = [bar]
 print(foo.cache, bar.parent)


 test()
 gc.collect()
 print(len(gc.garbage))

 gc.set_debug(gc.DEBUG_LEAK)
 gc.collect()
 print(len(gc.garbage))

 test()
 gc.collect()
 print(len(gc.garbage))
 }}}

 Results in following output

 {{{
 {'bars': [<__main__.Child object at 0x6f520cdd90>]} <__main__.Parent
 object at 0x6f520cd6d0>
 0
 0
 {'bars': [<__main__.Child object at 0x6f520b32d0>]} <__main__.Parent
 object at 0x6f520b1fd0>
 gc: collectable 
 gc: collectable 
 gc: collectable 
 gc: collectable 
 4
 }}}

 Removing the `gc.set_debug` statement, the `gc.garbage` is always empty,
 so it looks like à side effect of `DEBUG_LEAK`.

 As per the `gc` documentation:

 {{{
 To debug a leaking program call gc.set_debug(gc.DEBUG_LEAK). Notice that
 this includes gc.DEBUG_SAVEALL, causing garbage-collected objects to be
 saved in gc.garbage for inspection.
 }}}

 So, using `DEBUG_LEAK` leads to collected objects to be present in
 gc.garbage. So, I would say that looking at `gc.garbage` in this case does
 not identifies a memory leak. On the contrary, it shows objects that were
 garbage collected
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e19d62d2e-5094eb02-7637-4d38-b9a5-90d10ac10694-00%40eu-central-1.amazonses.com.


Re: [Django] #35279: Memory Leak with `prefetch_related`

2024-03-07 Thread Django
#35279: Memory Leak with `prefetch_related`
-+-
 Reporter:  Ken Tong |Owner:  nobody
 Type:   |   Status:  new
  Cleanup/optimization   |
Component:  Database layer   |  Version:  4.2
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  memory leak  | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Mariusz Felisiak):

 * component:  Uncategorized => Database layer (models, ORM)
 * stage:  Unreviewed => Accepted
 * type:  Bug => Cleanup/optimization

Comment:

 Interesting, thanks for the report. Tentatively accepted for further
 investigation.
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e18b8a921-3c1c286d-dd90-4edd-94bc-58de8c329719-00%40eu-central-1.amazonses.com.


Re: [Django] #35279: Memory Leak with `prefetch_related`

2024-03-07 Thread Django
#35279: Memory Leak with `prefetch_related`
---+--
 Reporter:  Ken Tong   |Owner:  nobody
 Type:  Bug|   Status:  new
Component:  Uncategorized  |  Version:  4.2
 Severity:  Normal |   Resolution:
 Keywords:  memory leak| Triage Stage:  Unreviewed
Has patch:  0  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+--
Comment (by Ken Tong):

 Hi Team,

 So far I am adding the code below in the appropriate lines in order to fix
 the memory leak in my projects. Hopefully there will be a fix and
 documented way to properly clean up the cache.

 {{{
 foo._prefetched_objects_cache.pop("bar_set")
 }}}

 Thank you for your attention!
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e18641c84-3c729fb1-88db-45b0-a917-3e142a731ce5-00%40eu-central-1.amazonses.com.