Heartworms and what (if anything) to administer to prevent them are a controversial topic.
If you are giving heartworm medication and live in the US, here's a link to information about when to give it with a map that shows how many months it is needed, depending on which part of the country you live in:
Please note that the Whole Dog Journal, which is widely trusted as a good source of information on holistic approaches to dog health, has an article in Feb 2006 that says of all the things you might decide to treat in various ways, this is really the one thing that must be treated using the commercial preparations as the consequences of not insuring the dog is covered during vulnerable periods are pretty horrific. If you have ever seen a picture of a heartworm infested heart, you will understand why. It is like the chambers are full of writhing spaghetti. Once a dog has adult heartworms, it is very hard to get rid of them and the treatment for this poses risks to the dog's health. Hecne prevention is crucial.
An excerpt from the article:
Whole Dog Journal: http://www.whole-dog-journal.com/Heartworm: Don't Take it Lightly
This is one aspect of canine healthcare for which conventional medicine offers the best -- and perhaps the only truly reliable -- prevention and treatment protocols.
Some argue, but...
As the co-moderator of an e-mail list on dog health and nutrition, I frequently see people allege that as long as you have a healthy dog, feed a raw diet, and do not over-vaccinate, your dog will not get heartworms. If only this were true! These measures may help to some degree, but they are not foolproof. The only way to know for sure that your dog is protected is to give heartworm preventatives.