question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a memory leak in the hello world example?

See original GitHub issue

I modified the Hello World example a tiny bit to track the memory usage.

#!/usr/bin/env python3
import gc
import os
import justpy as jp
import psutil

def hello_world():
    wp = jp.WebPage()
    process = psutil.Process(os.getpid())
    gc.collect()
    wp.add(jp.Div(text=f'memory: {process.memory_info().rss:,} bytes'))
    return wp

jp.justpy(hello_world)

It looks like there is a leak since the number keeps growing when reloading the page. This already happens with JustPy 0.2.x. Explicitly setting temp=True or delete_flag=True doesn’t help.

Weirdly, jp.WebPage.instances are not growing. So, what else could hold the page or div objects? Or am I doing something completely wrong measuring the memory?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
elimintzcommented, Sep 16, 2022

Ok, will check this more. This is interesting: https://github.com/tiangolo/fastapi/issues/4649 Could be a starlette issue. The dictionaries with the webpages, websockets and components are not growing. That is clear. And when you open multiple browser tabs and then close them you see that the dict entries decrease.

0reactions
elimintzcommented, Sep 17, 2022

I’ve kept the program running for almost 25 hours now, and it looks like eventually starlette reclaims the memory. Memory usage went down from startup. I think there is no issue here to take care of.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a memory leak in the hello world example? · Discussion ...
I modified the Hello World example a tiny bit to track the memory usage. ... It looks like there is a leak since...
Read more >
gtkmm/c++ first hello world example leaking memory
@Anton, a memory leak is memory to which you no longer have access, meaning you had a pointer to the memory, then without...
Read more >
[Solved]-c++ valgrind shows memory leak in hello world-C++
Coding example for the question c++ valgrind shows memory leak in hello ... This is memory reserved forever by linux system dynamic library...
Read more >
How To Detect and Prevent Memory Leaks | Scout APM Blog
Memory leak is the gradual loss of available computer memory when a program repeatedly fails to return memory it obtained for temporary use....
Read more >
What is Memory Leak? How can we avoid? - GeeksforGeeks
The consequences of memory leak is that it reduces the performance of the computer by reducing the amount of available memory.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found