Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

Call Dispose() after object removal?

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Call Dispose() after object removal?

Post by JakSparro98 » Sun Oct 16, 2016 11:59 pm

I was wondering if there is some impact on performance when I force a Dispose() call on objects implemented with IDispose or is it provided in the destructor itself?
0 x

Dumby Eggy
Superfighter
Superfighter
Posts: 66
Joined: Wed Dec 21, 2016 4:22 am
SFD Account: Huevon NEO
SFD Alias: Huevon SFD
Started SFD: PreAlpha 1.8.8
Location: Honduras
Gender:
Age: 21

Post by Dumby Eggy » Wed Dec 28, 2016 2:37 am

Exactly Jack what is the IDispose() call ?
0 x
HINT: You will not surprise me if you are good with snipers and magnums and katanas; but I will give my respect for someone who is a weapon-master. So don't wait any cheer marksmen...8-)

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Wed Dec 28, 2016 4:26 pm

Dumby Eggy wrote:Exactly Jack what is the IDispose() call ?
sorry I've misspelled, the Dispose() method is in the IDisposable class and is called to free the resources of the objects that are implementing this class.
But I'm wondering if it is automatically called after object destruction or I have to call it manually after I call Destroy() or Remove().
I make this question because I can't manage to solve the memory leak in my AI project.
0 x

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Post by Gurt » Wed Dec 28, 2016 7:40 pm

Dispose() is called internally as soon as an object is removed or destroyed. You don't have to think about it. I recommend that you don't call Dispose() at all unless you have implemented your own objects that needs to be disposed.
Sometimes .NET doesn't release memory until the next Garbage Collection is run. This won't happen until memory needs to be freed or until the next match restart. So depending on what you do you might see the memory raise up to 1 GB or more for SFD. Don't worry about it (unless you actually get out-of-memory crashes).
0 x
Gurt

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Wed Dec 28, 2016 10:14 pm

Gurt wrote:Don't worry about it (unless you actually get out-of-memory crashes).
Well, how can I say? It's happened, my bad scripting skills managed to reach the goal.

Image

Anyway, I'm going to release the current state of the code in a dedicated thread, also for promoting the posibility to change / improve it by the community but mainly to recieve any tip for the memory problem.
0 x

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Post by Gurt » Fri Dec 30, 2016 12:19 pm

Care to share the script so I can investigate? Maybe it's a problem in the SFD core code.
0 x
Gurt

Dumby Eggy
Superfighter
Superfighter
Posts: 66
Joined: Wed Dec 21, 2016 4:22 am
SFD Account: Huevon NEO
SFD Alias: Huevon SFD
Started SFD: PreAlpha 1.8.8
Location: Honduras
Gender:
Age: 21

Post by Dumby Eggy » Fri Dec 30, 2016 6:30 pm

Ehehehe, could you show me an example of using Dispose() ? I have no idea of how to adapt this.
0 x
HINT: You will not surprise me if you are good with snipers and magnums and katanas; but I will give my respect for someone who is a weapon-master. So don't wait any cheer marksmen...8-)

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Fri Dec 30, 2016 7:59 pm

Gurt wrote:Care to share the script so I can investigate? Maybe it's a problem in the SFD core code.
No problem, let me only to tidy up a bit the code and fill it with the right comment rate.
Dumby Eggy wrote:Ehehehe, could you show me an example of using Dispose() ? I have no idea of how to adapt this.
In plain language it's a method to call when you are about not to use object instances anymore but as Gurt Said you aren't to care about it unless you have particular objects from a class that implements it, in the other cases it is automatically called.
1 x

Dumby Eggy
Superfighter
Superfighter
Posts: 66
Joined: Wed Dec 21, 2016 4:22 am
SFD Account: Huevon NEO
SFD Alias: Huevon SFD
Started SFD: PreAlpha 1.8.8
Location: Honduras
Gender:
Age: 21

Post by Dumby Eggy » Fri Dec 30, 2016 11:34 pm

Jejeje yeah but I wanted a script example dude. anyway, thanks for explain it again
0 x
HINT: You will not surprise me if you are good with snipers and magnums and katanas; but I will give my respect for someone who is a weapon-master. So don't wait any cheer marksmen...8-)

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Sat Dec 31, 2016 2:35 am

Dumby Eggy wrote:Jejeje yeah but I wanted a script example dude. anyway, thanks for explain it again
here an example:

Download
0 x

Post Reply