There is the islamic point of view on this issue.
Although islamic sharia (law) is quiet on this issue, masturbation is permitted only on these circumstances.
-If you think you might commit adultery or fornification by watching porn or calling some girl over etc.
-When masturbating strictly do not think of sexual thoughts, this is just to relieve you. if you think of bad thoughts then the whole point is beaten, you've commit the sin.
So basically its to prevent you from doing the sin of adultery and fornification.