These are some additional thoughts on this passage that were prompted by a question from Carrie Gilshen.
Many theologians and historians argue over the location of this passage because it begins by saying, "the country of the Gerasenes", which was a Jewish region where there wouldn't have been any pigs. However, this passage ends by mentioning the formerly demonic man went into Decapolis, which was a gentile community, and thus we can assume there were pigs just as the passage says. The key to the ungodly nature of the people of the community is reflected in their asking Jesus to leave. It is to this area that Jesus deliberately decided to go, and perhaps with the sole purpose of healing the demon possessed man as a witness to the people.
The obvious witness was in the miracle of casting out the demons from the possessed man, and that he became rational afterwards. The key to the fact that the intent was to witness to the gentiles is confirmed in verse 20 where we are told that the man testified about Jesus in his community.
Most commentaries miss the second aspect of this witness, and that is from the pigs. The demon possessed man became demon possessed because he didn't rely upon the power of God, but when he did, he was healed. Jesus knew the evil intent of the demons in asking for permission to enter the pigs. He permitted it, not because he hated pigs, but because of the witness of God that they would present.
If a believer were to be possessed, and he or she died, the evil spirit would leave the person independently at the same time as his or her spirit, and the person would still go to heaven. The possessed man didn't run off the cliff into the sea and drown himself to free himself of the demons, but the pigs did. I personally believe that the pigs had more faith in God than the man, and this is the reason that the people were so afraid of the message Jesus was presenting to them.
When the pigs died, they went to heaven, but the demons went to the very place they didn't want to go.
I hope this helps.
In the Love of the Lord,