I have come across the term "garbage disposal" and now I'm worried about using up too much memory. Apparently (correct me if I'm wrong) every time an object is created, memory is reserved for it, and that object must be properly disposed of if not needed anymore. My question is if one should avoid instantiating objects then whenever possible. For example, if a function requires a coordinate as arguments, should I have example(int x,int y) or is it okay to have example(Point p) and during the actual call I do something like example(new Point(5,5)); I'm worried about not slowing down the application, so I would like to know if having primitives as arguments is better than having objects which will usually be instantiated on the spot
Aucun commentaire:
Enregistrer un commentaire