LibLoad and LibFree Best Practices

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
AndrewT
Junior Coder
Posts: 38
Joined: Thu Sep 17, 2015 6:06 pm

LibLoad and LibFree Best Practices

Post by AndrewT » Wed Dec 27, 2017 9:33 pm

So in the MS Manual it says:
Libraries loaded with LibLoad should always be freed with a call to LibFree after being used.
I have a program that does a LibLoad>user32.... at the beginning of the program and then LibFunc>user32,FindWindowA.... several times within the program.

My question is should I be using the LibLoad and LibFree commands at the beginning and end of every LibFunc instance, or can I do one LibLoad at the very beginning and one LibFree at the very end?

What are the potential consequences of using a LibLoad without a LibFree?

Thanks,
AndrewT

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: LibLoad and LibFree Best Practices

Post by JRL » Thu Dec 28, 2017 5:50 pm

My experience has been that the standard Microsoft libraries such as User32.dll are always preloaded by the operating system and do not need to be loaded using LibLoad>. LibLoad> is really meant for third party libraries.

But, to answer the question, in a particular script id LibLoad> is used to load a specific dll file it only needs to be loaded once and only needs to be freed once.

The consequence if failing to free the library function is a small bit of memory consumed. It will be restored on your next computer reboot.

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: LibLoad and LibFree Best Practices

Post by Marcus Tettmar » Fri Dec 29, 2017 11:46 am

If you are doing lots of LibFunc calls on the same DLL then, yes, in theory, using one LibLoad at the start and one LibFree at the end might be marginally faster, since the DLL would not need to be loaded for every call. Whether you notice any difference or not is questionable.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts