# Why does this StreamPlot evaluation cause a crash/memory wipe?

Bug introduced in 11.3 or earlier and persisting through 12.0.0 or later

EDIT: Reported to Wolfram Support, currently CASE:4238258.

For some reason, attempting to evaluate a simple StreamPlot will not only cause the StreamPlot evaluation to "fail" (although no error message is outputted), it will also completely wipe any variables that were generated by Mathematica that session, even if they were unrelated to the StreamPlot.

The following single line of code replicates the issue:

StreamPlot[{v, -Sin[x]*(1/2 - 10*Cos[8*0.525858])}, {x, Pi - 0.05, Pi + 0.05}, {v, -0.05, 0.05}, StreamPoints -> Fine]


Making the plotting range bigger prevents the issue for this case, but it will then occur again for different values in the cosine term. There doesn't appear to be any kind of singularity or obvious scaling issue in the expression, either—is there a simple workaround/fix or is this a bug?

To exemplify the strangeness of the issue, the following nearly identical expression will run just fine:

StreamPlot[{v, -Sin[x]*(1/2 - 10*Cos[8*0.496686])}, {x, Pi - 0.05, Pi + 0.05}, {v, -0.05, 0.05}, StreamPoints -> Fine]

• Funny example. What is your version? – Alex Trounev Mar 23 '19 at 22:48
• The symptoms you describe are of a crash, not a "memory wipe." – Michael E2 Mar 23 '19 at 22:53
• @AlexTrounev I am running Mathematica 11.3, Student Edition. Also, an evaluation of MemoryAvailable[] at the beginning of a blank session will return about 3 GBs. – aghostinthefigures Mar 23 '19 at 22:55
• Remove the StreamPoints -> Fine option and it seems to work fine. So it's probably running out of memory when it tries to calculate with more points. – bill s Mar 23 '19 at 22:56
• I also noticed that in version 11.3 there are problems with memory. In this example, 12 GB was used. – Alex Trounev Mar 23 '19 at 22:59

Here is the simplest example I've found that causes trouble (it uses a lot of memory):

(* runs forever, causes crash *)
StreamPlot[{v, 5 x}, {x, -0.05, 0.05}, {v, -0.05, 0.05}, StreamPoints -> Fine]


The number 5 is the smallest integer coefficient that causes the problem, though I didn't think it would be helpful to identify the minimal Real number.

A simple workaround is to use an interval that is not symmetric around the critical point:

StreamPlot[{v, 5 (x - Pi)},
{x, Pi - 0.05 + 10^-6, Pi + 0.05}, {v, -0.05, 0.05}, StreamPoints -> Fine]


The same trick works on the OP's example. I suspect that StreamPlot ends up trying to solve an IC that gets close to the equilibrium. I suppose it takes a large number of steps, although I'm not sure why there isn't a MaxSteps limit. It probably should be considered a bug.

• Thanks Michael—because your answer solves my example, I'll be sure to upvote and mark it correct very soon. I should note that I received a crash with your workaround on my original example for another parameter value in the cosine term, which means that the workaround is specific to some cases. – aghostinthefigures Mar 23 '19 at 23:31
• @aghostinthefigures I can't respond without a specific example. -- I found one, too, and the same trick worked if I change the interval to {x, Pi - 0.05 + 10^-5, Pi + 0.05}. So you might want to take the idea and play with it. – Michael E2 Mar 23 '19 at 23:34