Sound file : unloadSfx problem

Hi all,
I have loaded a sound file using:
self.mySound = loader.loadSfx(Constants.MYDIR+"/game/sound/abc.wav")
and it works perfectly fine. However when I try to unload it using:
loader.unloadSfx(Constants.MYDIR+"/game/sound/abc.wav"), the error I receive is : AttributeError: Loader instance has no attribute ‘unloadSfx’. What I know is that there is a function: def unloadSfx(self, sfx) but there is absolutely no info. available anywhere about it.
Please suggest what I can do to unload this sound file.

Thank you & Regards,

I’m not sure why you can’t call the unloadSfx() method, but it doesn’t really do very much anyway. Normally, Python reference counting will take care of unloading your sounds for you when you let them go away.


Hello drwr,
Thanks for your reply. This means that I should be fine just stopping the sound when required and have Python take care of the rest. That’s gr8!.
Thank you very much!


Hmm, I think he mains you have to delete them, either by letting them be garbage collected or by explicitly deleting them:

del yourSound

Naww. The “del” keyword is probably the most consistently misunderstood feature of Python. Get this: “del x” doesn’t delete x! It’s nothing at all like the C++ delete keyword, even though it looks so very much like it.

All del does is make the variable go out of scope. (Which will, incidentally, result in x being deleted, if there are no other references.) But in many cases, the variable is about to go out of scope anyway. So del is very often a do-nothing operator.

There are times that del is particularly useful. You may need it, for instance, to break circular references between two objects (e.g. a.ref = b; b.ref = a. With this kind of circularity, you’ll have to explicitly del either a.ref or b.ref, or wait for garbage collection to discover the cycle). del is also useful to remove entries from a dictionary or a list.

But otherwise, del is almost completely unneeded. Normal Python reference-counting should take care of deleting things when you let go of their pointers.


Ah, ok, sorry. I thought “del” decreased the reference count and thus made it garbage-collectible, if the refcount would reach zero.

Yes, indirectly, that is indeed what it does. But Python’s reference-counting system is designed so that that’s what will generally happen anyway, whether you use del or not.