Should I put a try-finally block after every Object.Create?

后端 未结 8 1366
青春惊慌失措
青春惊慌失措 2021-02-04 17:11

I have a general question about best practice in OO Delphi. Currently, I put try-finally blocks anywhere I create an object to free that object after usage (to avoid memory leak

8条回答
  •  [愿得一人]
    2021-02-04 17:47

    It's definitely best practice to use try-finally.

    In the event of an exception being raised, that object will be freed.

    As for performance: measure before you optimise.

提交回复
热议问题