Programming Problems with JSyn

Please check the List of Known Bugs
For sound quality issues, pops, clicks, distortion, etc., click here.


If you get a "Null Pointer Exception", it might be because:

If the sound continues after you leave the Applet, it might be because:

If the scope or other windows stay open after you leave the Applet, it might be because:

If you get an error "startEngine() not called" or "invalid token"...

If units suddenly stop making sound ...

Have you ever been playing a JSyn piece for 5 or 10 minutes and have the sound suddenly stop? Here is a possible explanation.

In 'C', you allocate memory using malloc() and free it using free(). Java allocates memory for you when you use "new" to create an object or an array. You do not explicitly free the memory in Java. Java detects when there is no code that references the object and makes the object available for garbage collection. There is a problem with JSyn objects in that they have a native component that may be in use even when the Java level is no longer referenced.

Consider the following piece of code:

class MyThang
        LineOut  lineOut;
        void makeIt()
                lineOut = new LineOut();
        /* Note sineOsc not referenced outside this method! */
                SineOScillator sineOsc = new SineOScillator();
                sineOsc.output.connect( 0, lineOut.input, 0 );
As long as you keep a reference to the MyThang then the lineOut will have a reference and not be garbage collected. But the sineOsc is up for grabs as soon as you exit makeIt(). There are no references even though the oscillator is making sound. When Java decides to, which might be several minutes after calling makeIt(), the SineOscillator will be deleted. This will cause the native component to also be deleted and the sound will stop. This generally not happen during testing if you run a short test. But as soon as you are up on stage and playing for 5 or 10 minutes then the sound will sudenly stop and you will be left staring at your laptop in puzzlement.

To prevent this, either declare all SynthObjects at the class level instead of the method level, like "lineOut" versus "sineOsc" above. Or call:


which will cause a reference to all JSyn SynthObjects to be stored in a vector to prevent any unexpected garbage collection. The delete() method will delete the object and remove the reference from the vector. All tracked objects that are left will be deleted automatically when you call Synth.stopEngine().

Or you can disable the ability of the garbage collector to delete the native portion of SynthObjects. Try calling:

SynthObject.enableDeletionByGarbageCollector( false );

If your Applet works for Internet Explorer but fails, or gives a NullPointerException, under Netscape...

  • You may be using an older obsolete version of Netscape,
  • or you forgot to EMBED the plugin for Netscape browsers,
  • If you get a java.lang.OutOfMemoryError

    Java objects and arrays that live inside the Java virtual machine are allocated from a special Java heap. When you run out of memory, it is automatically expanded. But you may eventually run out of physical or virtual memory. Then you will get a "java.lang.OutOfMemoryError". If so then make sure you are not saving references to objects that you no longer need. A typical mistake is saving references to objects in Vectors while you use them but forgetting to remove them when you are done. See also "SynthException: MemoryAllocationFailed".

    If you cannot find an answer to your question on this website, then please ask on the JSyn list.

    © 2001 SoftSynth.com