The method Object.defineProperty
(see here) accepts as third argument a "descriptor".
What is a descriptor?
Yes, close your file descriptors and free all heap memory, even if you know that the OS will clean it up - that way, when you run valgrind or some similar tool, you don't get a lot of noise in the results, and you can easily recognize "legit" fd leaks.
As long as your program is running, if you keep opening files without closing them, the most likely result is that you will run out of file descriptors/handles available for your process, and attempting to open more files will fail eventually.
A file descriptor is a number that uniquely identifies an open file in a computer's operating system. It describes a data resource, and how that resource may be accessed. When a program asks to open a file — or another data resource, like a network socket — the kernel: Grants access.
The close() function closes a descriptor, fildes. This frees the descriptor to be returned by future open() calls and other calls that create descriptors. When the last open descriptor for a file is closed, the file itself is closed.
A property descriptor can be of two types: data descriptor, or accessor descriptor.
Mandatory properties:
value
Optional properties:
configurable
enumerable
writable
Sample:
{ value: 5, writable: true }
Mandatory properties:
get
or set
or bothOptional properties:
configurable
enumerable
Sample:
{ get: function () { return 5; }, enumerable: true }
A descriptor is something that describes something. In this case it's just a plain object ({...}
) with certain fields, that describes how the property should behave. Read further down the page to see what fields you can use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With