Legacy GM When working with sockets, what do I need to do to avoid a memory leak?

T

Tirous

Guest
I've been learning to do networking in and one thing I've got a question.

The function network_destroy obviously exists due to sockets being dynamically allocated, but there are multiple different ways to create sockets, with some of these methods making sockets look like non-dynamically allocated objects, and GameMaker doesn't make it clear which/when you need to use network_destroy on said sockets to avoid a memory leak.

Example #1: When a server gets a new client, the async event provides a new socket object for said client. What do I need to do to safely dispose of sockets created like this? Do I need to use network_destroy on the client's disconnect? At the server shutting down? Or will GMS do all this for me? If it is dynamically allocated and I just ignore the handle given to me by the async event, did I just cause a memory leak?

Example #2: When network_create_server returns a negative number due to failure, is this a socket? Or is it just a failure signal?

These examples are only a few of the issues I've found with using networking in GameMaker. I get that it assumes you already understand sockets and so doesn't explain much about networking, but I would really appreciate if that assumption didn't extend to not telling you if things are dynamically allocated and thus if they can cause memory leaks or not.

So ya, long story short, given the multiple ways that socket objects can be create: server creation; client-side connection; server-side client connection sockets given in async events; etc. What do I need to do to safely dispose of all of these sockets to avoid a memory leak? Do I need to use network_destroy on ALL of them? Or are some automatically handled? Again, GMS provides no documentation on this and seems to go out of its way to make it needlessly confusing.

Thanks in advance! :D
 

Yal

šŸ§ *penguin noises*
GMC Elder
Example #2: When network_create_server returns a negative number due to failure, is this a socket? Or is it just a failure signal?
Usually the IDs map to array entries further down the line, so it makes no sense for a negative number to be a valid object. The negative number is just a number.
 
Top