Reputation: 370
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
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