skpaik
skpaik

Reputation: 370

Python: Which will take less memory and execution is fast?

I have a ResponseMessageService() class, Which have several methods. I need only one method.

Then Which is better?

call that method directly? by

    ResponseMessageService().WrongRegMsg(data="Your Reg ID is wrong!")

or take a object

    response_message_service = ResponseMessageService()

Then call

    response_message_service.WrongRegMsg(data="Your Reg ID is wrong!")

Which will took less memory and execution is first?

Upvotes: 1

Views: 87

Answers (1)

Quan To
Quan To

Reputation: 696

Regarding your question,

ResponseMessageService().WrongRegMsg(data="Your Reg ID is wrong!")

would likely to take less memory.

Assigning the instance to a variable makes it retained in the memory, at least until the variable's name is unbound, for example, by using del response_message_service

Upvotes: 1

Related Questions