Unfortunately, in English there are many exceptions to the so-called rules.
Usually we use the definite article to indicate a specific instance of the type of thing we're describing:
I ate the apple that you were saving.
Sometimes, we use the definite article to mean the exact opposite, that is, an unspecified instance of the type of thing described:
I took a walk in the woods - the woods does not designate a specific area, but actually refers to a wooded area whose location is not pertinent
I have to stop at the store on my way home - the store really means any old store, it doesn't matter which.
Every Friday, I go to the cinema - Which cinema? Any cinema.
Whenever I'm at the beach, I build a sandcastle - The speaker would not mean "whenever I'm at this one specific beach I build a sandcastle," but instead "any time I'm at any beach, I build a sandcastle."
I try to go to the gym every day of the week. I go to a gym near my office during the week, and one near my house on the weekend - Here the gym clearly cannot refer to a specific gym, because two different locations are mentioned.
All of these examples use the definite article, but they describe a generic location, or a generic activity. "Going to the gym" can sometimes mean moving your body through space such that you transport yourself to a specific building, which is a specific gym. But just as often (or perhaps more often) it means working out at some unspecified gym.
The real trouble is, some generic locations/activities use the definite article and some use no article, e.g. I'm going to school, I'm going to work, I'm going home, I go to university, I'm going to practice, etc.
How do you know which is which? Memorization.