alsa - mem leak?
http://git.alsa-project.org/?p=alsa-lib.git;a=blob;f=MEMORY-LEAK;hb=HEAD says:
Memory leaks - really?
----------------------
Note that some developers are thinking that the ALSA library has some memory
leaks. Sure, it can be truth, but before contacting us, please, be sure that
these leaks are not forced.The biggest reported leak is that the global configuration is cached for
next usage. If you do not want this feature, simply, call
snd_config_update_free_global() after all snd_*_open*() calls. This function
will free the cache.
ALSA: snd_pcm_hw_params_free() causing memory error
The snd_pcm_hw_params_alloca()
documentation says:
allocate an invalid
snd_pcm_hw_params_t
using standard alloca
The standard alloca()
function allocates memory from the stack; this memory gets automatically freed when the function exits.
You can use snd_pcm_hw_params_free()
only for an object allocated with snd_pcm_hw_params_malloc()
.
Why there's a mem leak and how to fix it?
You free o2
twice. Once as a result of the message and once from the destructor.
You think you are setting o2
to nil
when you call FreeMyObject
but you are not. You are in fact setting msg.lParam
to 0.
o2
is a variable holding a reference to an object. You are passing the value of o2
and when you pass by value you cannot modify the variable whose value you passed. So you need to pass a reference to o2
. To do so you need to add an extra level of redirection and pass a pointer to o2
, like so:
if(msg.message=6) then begin
FreeAndNil(PObject(msg.lParam)^);
Exit;
end;
...
PostThreadMessage(l.ThreadID, 6, 0, LPARAM(@my.o2));
You don't need FreeMyObject
, you can just call FreeAndNil
directly. And you don't need to pass an instance in the message.
I hope your real code isn't quite as weird as this! ;-)
Kotlin/Native, mem leak hunting when valgrind dumps core
In most cases pure Native programs without interop or atomic references shall not leak. Good approach is to create minimal reproducer and report to JetBrains using issue tracker. As Valgrind shall not crash as well, report to Valgrind devs may help as well.
Related Topics
Elf Header or Installation Issue with Bcrypt in Docker Container
How to Detect Usb Drive Insertion in Linux
Installed Go Binary Not Found in Path on Alpine Linux Docker
Need Explanations for Linux Bash Builtin Exec Command Behavior
Limiting the Time a Program Runs in Linux
Create a Static Haskell Linux Executable
Detecting a Chroot Jail from Within
Delete a Column from a Delimited File in Linux
Using Ld_Preload Mixed 64Bit/32Bit Environment in Linux
How to Wrap Lines Within Columns in Linux
Why Does Perf Show That Sleep Takes All Cores
Amazon Linux: "Apt-Get: Command Not Found"
Linux Shell to Restrict Sftp Users to Their Home Directories