﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36137	Simple performance test using timeit and django.test.Client leads to using all available memory	Vinay Sajip		"Running this script:

{{{
#!/usr/bin/env bash
rm -rf minimal env
python3 -m venv env
env/bin/pip install django
env/bin/django-admin startproject minimal
cd minimal
../env/bin/python manage.py startapp basic
cat << EOF > basic/tests.py
import timeit

from django.test import TestCase, Client

class MinimalTestCase(TestCase):
    def test_render_performance(self):
        n = 2000000
        t = timeit.timeit(setup=""from django.test import Client; c = Client(headers={'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:134.0) Gecko/20100101 Firefox/134.0'})"",
                          stmt=""c.get('/admin/')"", number=n)
        print(f'{int(t * 1000/n)} msecs')
EOF
../env/bin/python manage.py test

}}}

causes all of the memory in the machine to be used up. This is unexpected, as the response returned from the `c.get('/admin/')` call isn't stored anywhere and should be garbage collected, and it's not clear where the memory leak is. Once the memory usage goes to near 100%, the swap starts going up and the test grinds to a crawl.

Tested with Django 5.1.5, Python 3.10.12 on a Linux Mint system with 4GB of memory."	Bug	closed	Testing framework	5.1	Normal	invalid		Vinay Sajip	Unreviewed	0	0	0	0	0	0
