Skip to content

Memory Leak #135

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

Open
glowww opened this issue Mar 14, 2025 · 1 comment
Open

Memory Leak #135

glowww opened this issue Mar 14, 2025 · 1 comment

Comments

@glowww
Copy link

glowww commented Mar 14, 2025

When making requests that return large responses, memory usage goes through the roof. It doesn’t seem to scale properly with the response size.

Script to reproduce

import psutil
import tls_client


def memory_usage():
    return psutil.Process().memory_info().rss // (1024 ** 2)


print(f"Before request: {memory_usage()}MB")
response = tls_client.Session().get(
    url="https://platform.tonybet.com/api/event/list",
    params={
        'limit': 200,
        'main': 0,
        'page': 1,
        'oddsExists_eq': 1,
        'period': 0,
        'lang': 'en',
        'relations[]': [
            'odds',
            'competitors',
            'players',
            'variants',
            'league',
            'sport'
        ],
    },
)
print(f"After request: {memory_usage()}MB")
print(f"Response size: {len(response.text.encode()) // (1024 ** 2)}MB")

Output

Before request: 27MB
After request: 1470MB
Response size: 73MB

Expected Behavior
A 73MB response shouldn’t cause memory usage to jump by over 1GB. Some increase is expected, but this seems excessive.

@JTJag
Copy link

JTJag commented Mar 29, 2025

This issue appears to be caused by the underlying dependency bogdanfinn/tls-client, rather than this project itself.

It has been discussed in the upstream repository here:
bogdanfinn/tls-client#165

The maintainer responded with the assumption that the increased memory usage may not be a true memory leak, but rather due to how Python's garbage collector works in combination with how the library is used (especially in the main process or without proper scoping).

They suggest wrapping memory-heavy calls in separate functions to allow Python to release memory more effectively, and confirmed that freeMemory() should be called to help clean up.

For reference, here is their comment and workaround:
bogdanfinn/tls-client#165 (comment)

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

No branches or pull requests

2 participants