Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak when creating system #17

Open
adwilson10 opened this issue Jul 3, 2014 · 5 comments
Open

Memory leak when creating system #17

adwilson10 opened this issue Jul 3, 2014 · 5 comments
Labels

Comments

@adwilson10
Copy link
Contributor

From [email protected] on February 28, 2013 16:20:21

Suppose I create a system object and then overwrite it. The memory allocated to the first object will not be freed and extra memory will be allocated for the second system object, even though no references to the first object exist. Forcing a garbage collection by running gc.collect() does not work. The large objects that are left behind are almost certainly the third and fourth derivatives of g and vb as they appear in _structure_changed() in frames.py

Original issue: http://code.google.com/p/trep/issues/detail?id=17

@adwilson10
Copy link
Contributor Author

From [email protected] on February 28, 2013 14:41:10

Can you attach an example script that demonstrates this?

Owner: [email protected]

@adwilson10
Copy link
Contributor Author

From [email protected] on February 28, 2013 15:16:54

Here is one. Adjust the number of links in case what I used overloads your machine.

Attachment: memory_leak.py

@adwilson10
Copy link
Contributor Author

From [email protected] on February 28, 2013 20:01:33

The system isn't being recovered by the garbage collector, most likely because of the cyclic references between child frames and their parents, and between the frames and the system. Python provides a C interface that addresses this problem at http://docs.python.org/2.7/c-api/gcsupport.html . I won't have time to fix this for a while, but hopefully the changes made for issue #18 will keep this from being a problem.

@adwilson10
Copy link
Contributor Author

From [email protected] on February 28, 2013 20:04:54

Also, the way that you are measuring memory usage in that script is not correct for this. maxrss reports the max usages of a process over its entire lifetime, so it cannot go down even when the memory is freed properly. This code from stack overflow ( http://stackoverflow.com/questions/897941/python-equivalent-of-phps-memory-get-usage ) seems to work:

def memory_usage():
"""Memory usage of the current process in kilobytes."""
status = None
result = {'peak': 0, 'rss': 0}
try:
# This will only work on systems with a /proc file system
# (like Linux).
status = open('/proc/self/status')
for line in status:
parts = line.split()
key = parts[0][2:-1].lower()
if key in result:
result[key] = int(parts[1])
finally:
if status is not None:
status.close()
return result

@adwilson10
Copy link
Contributor Author

From [email protected] on March 04, 2013 08:17:30

This is not a huge issue for now, since for what I'm doing there really is no need to delete and rebuild the system. Memory measurement method appreciated as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant