python / cpython

The Python programming language
https://www.python.org/
Other
60.24k stars 29.15k forks source link

PRIVATE: interned->ma_table never free'd (PR#361) #32736

Closed 50eff062-408a-4098-b1b2-8222303b9d0c closed 23 years ago

50eff062-408a-4098-b1b2-8222303b9d0c commented 23 years ago
BPO 210666
Nosy @gvanrossum

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = 'https://github.com/gvanrossum' closed_at = created_at = labels = [] title = "PRIVATE: interned->ma_table never free'd (PR#361)" updated_at = user = 'https://bugs.python.org/anonymous' ``` bugs.python.org fields: ```python activity = actor = 'gvanrossum' assignee = 'gvanrossum' closed = True closed_date = None closer = None components = ['None'] creation = creator = 'anonymous' dependencies = [] files = [] hgrepos = [] issue_num = 210666 keywords = [] message_count = 4.0 messages = ['326', '327', '328', '329'] nosy_count = 3.0 nosy_names = ['gvanrossum', 'nobody', 'jhylton'] pr_nums = [] priority = 'low' resolution = 'wont fix' stage = None status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue210666' versions = [] ```

3772858d-27d8-44b0-a664-d68674859f36 commented 23 years ago

Jitterbug-Id: 361 Submitted-By: cfandrich@8cs.com Date: Fri, 16 Jun 2000 20:08:33 -0400 (EDT) Version: 1.5.2 OS: Windows

I'm embedding Python in an application. For now, all I'm doing is initializing and finalizing Python.

When I run my app I get a memory leak of 12288 bytes. The memory is malloc'ed by dictresize() which is called by PyDict_SetItem() which is called by PyString_InternInPlace().

For now, I've added 
    PyDict_Clear(interned);
    interned = NULL;
to PyString_Fini().  So far it works fine, but I don't know if it's safe to do
in the grand scheme of things.

-Chris

\==================================================================== Audit trail: Tue Jul 11 08:26:01 2000 guido moved from incoming to open

3772858d-27d8-44b0-a664-d68674859f36 commented 23 years ago

From: "M.-A. Lemburg" \mal@lemburg.com\ Subject: Re: [Python-bugs-list] PRIVATE: interned->ma_table never free'd (PR#361) Date: Sat, 17 Jun 2000 10:53:20 +0200

cfandrich@8cs.com wrote:

Full_Name: Christopher Fandrich Version: 1.5.2 OS: Windows Submission from: (NULL) (208.41.174.4)

I'm embedding Python in an application. For now, all I'm doing is initializing and finalizing Python.

When I run my app I get a memory leak of 12288 bytes. The memory is malloc'ed by dictresize() which is called by PyDict_SetItem() which is called by PyString_InternInPlace().

For now, I've added PyDict_Clear(interned); interned = NULL; to PyString_Fini(). So far it works fine, but I don't know if it's safe to do in the grand scheme of things.

I would suggest adding code to dealloc the interned dict iff it is empty after the sweeping action in PyString_Fini(). I have a feeling that this is not the case though, since interned strings are used quite a lot in the core interpreter (e.g. in classobject.c) and these are usually not recovered.

Perhaps we ought to add some code which takes care of cleaning up all remaining garbage left over after the call to call_ll_exitfuncs() in Py_Finalize(), e.g. force free'ing of all interned strings and cached ints/floats and associated free lists or dicts.

We'd need new APIs in string|float|intobject.c to implement this.

Thoughts ? Patches ?

-- Marc-Andre Lemburg


Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/

03bde425-37ce-4291-88bd-d6cecc46a30e commented 23 years ago

Please do triage on this bug.

gvanrossum commented 23 years ago

You shouldn't worry about this memory leak. The interned dict is shared by all interpreters and it's not safe to clear it. If you repeatedly initialize and finalize Python, you shouldn't see the memory leak increase.

(What leak detection tool do you use anyway? Since the interned dict is still accessible through a global, it shouldn't be called a leak!)