You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As described in docs, the //go:embed directive allows us to embed multiple files into a dedicated File System that satisfies the io.FS interface.
I've encountered a situation where I would like to embed (namely hide) certain large images into the executable to load them into the memory at the very start of my application, but as soon as I decode those images (or use embedded files) I don't need them in my memory anymore.
If I set the value of the embed.FS variable to embed.FS{} it would wipe every embedded file from the memory, but there is no way to remove a particular one.
The fs.File returned by embed.FS's Open() does nothing at Close() which is absolutely understandable, that's why I would like to propose a new function in the embed.FS struct that would erase a file (or dir) at given name, my suggestion would be Dispose(name string) error.
The text was updated successfully, but these errors were encountered:
Just so you know, embed hides absolutely nothing, if your files are recognisable formats it will be trivial to use something like binwalk to extract them.
If they aren't you would need to extract the symbol which is only slightly harder. Someone will probably make some turn key outbed cli that extract all files from a go binary one day.
🙂
That a 👎 for me, embed.FS data is stored in a read only portion of executable, it's not fully loaded into ram it's lazily swapped on demend by the OS, maybe this is broken and data is kept alive more than it should but then the fix would be to change some linking parameters, or maybe madvise this part of memory (with refcounting based on Close), whatever prevents memory from being released.
IMO this is between,
everything is happenning as it should (you don't see the memory usage being reduced because your OS does not feel under memory pressure)
or a bug prevents the OS from reclaiming the memory.
Having embed.FS being readonly allows to put all the internal data structures in read only part of the exectuable that can be swapped in and out of the ram when needed, if you start having ways to remove files you would need to always keep alive objects telling what is still there and what isn't.
As described in docs, the
//go:embed
directive allows us to embed multiple files into a dedicated File System that satisfies theio.FS
interface.I've encountered a situation where I would like to embed (namely hide) certain large images into the executable to load them into the memory at the very start of my application, but as soon as I decode those images (or use embedded files) I don't need them in my memory anymore.
If I set the value of the
embed.FS
variable toembed.FS{}
it would wipe every embedded file from the memory, but there is no way to remove a particular one.The
fs.File
returned byembed.FS
'sOpen()
does nothing atClose()
which is absolutely understandable, that's why I would like to propose a new function in theembed.FS
struct that would erase a file (or dir) at given name, my suggestion would beDispose(name string) error
.The text was updated successfully, but these errors were encountered: