Heartworm prevention needs to be constant - it is spread by mosquitos. All dogs need to be treated for life to prevent infection. Heartworm infections are very detrimental to any dog's health, and treating an established infection is costly and dangerous, prevention is key. Discuss the reccomended protocol with your veterinarian.
Be sure to purchase any pet medications through your vet - discount pet medication sites often sell expired or counterfit products that will not protect your pet, and will not take responsibility for the inevitable adverse health effects of using worthless/expired medications.