This is a tough problem with no easy answer. Ive 2 friends with heroin problems that I fear may never fully stay clean. I don't think that jail is the right answer though.
If jail was structured around rehabilitation of the roots causes that led the individuals into the anti-social behavior that requires their isolation then it would be the proper place for someone who has been overcome by problems like this. Instead jail is punitive hell, meant to further isolate and devastate the individuals it consumes to intimidate the rest of the population.
And it's punitive forever. Your employment prospects once you have a felony conviction are severely limited.
So you're suggesting that anyone who is addicted to heroin should be jailed, as long as the prison system is trying to rehabilitate them from this alleged 'anti-social behaviour'? Surely a better system is to treat the addicts symptoms with programs that provide methadone or buprenorphine replacement and management, and also provide therapy or counselling as required.
Legalization would help in a couple ways. It should free up funds to redirect to something more productive around rehab. And, at least for newer addicts, it keeps them from having an arrest record that makes employment impossible. As it stands, it's quite difficult for anyone caught using to break the cycle. They can't get work, which leads to depression, which leads to continued drug use.