phetsims / neuron

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

Is this a memory leak? #18

Closed jbphet closed 9 years ago

jbphet commented 9 years ago

During the code review, @samreid and I came across the following code, and neither of us was sure whether or not it would cause a memory leaks, since there is no explicit unlink. We should create a test and figure this out. I'm thinking that it is probably fine because the reference to the traveling action potential is eventually released, but it would be good to be certain.

initiateTravelingActionPotential: function() {
        var thisAxonMembrane = this;
        this.travelingActionPotential = new TravelingActionPotential( this );
        this.travelingActionPotential.crossSectionReachedProperty.lazyLink( function( reached ) {
          if ( reached ) {
            thisAxonMembrane.travelingActionPotentialReachedCrossSection = true;
          }
        } );

        this.travelingActionPotential.lingeringCompletedProperty.lazyLink( function( lingeringCompleted ) {
          if ( lingeringCompleted ) {
            thisAxonMembrane.removeTravelingActionPotential();
          }
        } );

        thisAxonMembrane.travelingActionPotentialStarted = true;
        thisAxonMembrane.travelingActionPotentialEnded = false;
        thisAxonMembrane.travelingActionPotentialReachedCrossSection = false;
      },
samreid commented 9 years ago

@AshrafSharf can you take a look and give your thoughts?

jbphet commented 9 years ago

I ran several memory profiling tests and reviewed the code, and am reasonably certain that this is not a memory leak. Other than code inspection, I did the following, all of which is good to do in order to verify that there are no memory leaks:

So, I think it's save to answer the title with a "no" and close the issue.