phetsims / blackbody-spectrum

"Blackbody Spectrum" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
1 stars 3 forks source link

Steady memory leak #72

Closed chrisklus closed 5 years ago

chrisklus commented 5 years ago

From https://github.com/phetsims/blackbody-spectrum/issues/33.

I recorded heap snapshots at one-minute intervals while the sim was fuzzing and found that there's a steady memory leak. These numbers are not concerning from a general size perspective, but the sim is growing a bit from its original size.

Test Memory Usage (MB)
Immediately after load 17.6
After 1 min of fuzz 21.0
After 2 min of fuzz 22.5
After 3 min of fuzz 22.7
After 4 min of fuzz 24.0
After 5 min of fuzz 23.9
After 6 min of fuzz 24.4
After 7 min of fuzz 26.6

@arnabp - @jbphet says that if you haven't done any memory profiling before, then you guys can look into this together. I'm also happy to help.

At first glance, I'm seeing a few possibilities to track down (Emitters, Properties):

image

jessegreenberg commented 5 years ago

I recently did memory profiling in https://github.com/phetsims/ohms-law/issues/124 and saw the heap snapshots grow from 25 to 32 MB over the course of ~4 hours or so but eventually stabilize at ~32 MB after about an hour. I am wondering if the same sort of memory profile would show up here after much longer fuzzing.

arnabp commented 5 years ago

Discussed this issue with @jbphet, he's following up on the issue linked above, and he'll update this issue as well

jbphet commented 5 years ago

I just tested this again, and there is a screenshot below that captures the results. I changed the test to go like this:

  1. Load with fuzz running, run for 2 minutes
  2. Take a snapshot (snapshot 1 below)
  3. Press the reset button, then take another snapshot (snapshot 2 below)
  4. Re-enable fuzzing, capture snapshots every minute for 5 minutes (snapshots 3-7)
  5. Press the reset button and take a snapshot (snapshot 8)

It seems to me that the most legitimate test is to compare snapshots 8 and 2, since some fuzzing has been done, but the sim is then restored to what should be its initial state. When this is done, we see 1.3 MB of memory growth. This isn't much, and is extremely unlikely to cause any problems for users. Also, I spot checked a number of additional allocations, and all of them looked to be in Scenery pools, such as the once shown in the screenshot.

In my judgement, the memory behavior is reasonable and there is no need to do any further investigation. Closing.

image