According to this
Vala doesn’t have garbage collection. It does reference counting.
I’m not exactly sure what the difference is between garbage collection and reference counting nor could I find a clear explanation.
Do I explicitly need to delete bmp and/or add a destructor to class Bmp?
IOW: does this code have a memory leak?
public void* run() {
while(true) {
if(detected) {
...
var bmp = new Bmp(800,800);
...
public class Bmp {
...
The code you have written is not a memory leak, but it is possible to write one. For instance:
Every time a
Foois assigned, a counter for that instance is incremented and decremented when it is unassigned. Becausefoo1andfoo2have references to each other, their counts will never go to zero, even if there are no references to them in the rest of the program. Theunownedkeyword makes a reference that not counted. So, a dangling pointer can be written as follows:If your object graph has no cycles, there will be no problem. If you have any circular references, you may leak memory if you do not clean up properly.