Well you should read the tutorial from Dealin or other guys for example from wc3campaigns. But whatever I give you a short introduction about how to remove leaks. All stuff you create ,which are handles, you should remove if you dont need it. Mostly you use in spells handles like "location" or "group". To remove/destroy those handles you must just enter the right function. For example when you want to remove a location enter: "call RemoveLocation(<location>)". JassCraft will help you alot when you dont know those function names. Because there you can enter a search word like destroy or remove and then you must just look where is the right function which you need to remove or to destroy a handle like a location or a group!
Link to JassCraft!
I hope I helped you!