They don't give out free heroin in SF. There are needle exchange programs, and a small number of safe usage sites. Also, you're assuming most of the addicts are heroin addicts. Quite a few of them are meth addicts, who are harder to reach, partially because the type of meth they're getting causes severe psychosis.
Giving meth addicts forms of meth that are produced more cleanly would reduce the level of psychosis and would further reduce the price of meth to a point where it may not be profitable to produce (it's already cheap to the point where it's nearly unprofitable - it requires massive volume).
Giving addicts access to clean drugs provides you an opportunity to help them, a place to keep them away from others while they're using, a way to ensure they don't die while using, reduces funding to organized crime, and removes their need to commit crimes to fund their habits.
You may see it as treating them poorly, but ultimately, you're doing them and the rest of society a benefit.