Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModbusClient.Available() Has memory leak #84

Open
3D-Lasers-Lab opened this issue Aug 4, 2022 · 2 comments
Open

ModbusClient.Available() Has memory leak #84

3D-Lasers-Lab opened this issue Aug 4, 2022 · 2 comments

Comments

@3D-Lasers-Lab
Copy link

Every time the Available() method is called the program uses about another 100k or RAM.

@PRIMETSS
Copy link

PRIMETSS commented Dec 5, 2022

Here is the associated code for ModbusClient.Available()

Doesn't look like either implement IDisposable System.Net.NetworkInformation.Ping so doubt using(System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping()) would help?
There are some cleanup Internal Dispose methods but they are not public.

Are you sure it's a memory leak and not just a delay until the Garbage Collector cleans it's up once goes out of scope?
100K does seem high, how did you check for that use?

public bool Available(int timeout)
{
// Ping's the local machine.
System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping();
IPAddress address = System.Net.IPAddress.Parse(ipAddress);

        // Create a buffer of 32 bytes of data to be transmitted.
        string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data);

        // Wait 10 seconds for a reply.
        System.Net.NetworkInformation.PingReply reply = pingSender.Send(address, timeout, buffer);

if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) return true; else return false; }

@Padanian
Copy link

Padanian commented Dec 6, 2022

Good morning. I never experienced this bug before, but to be completely honest timeout in Send(address, timeout, buffer); in System.Net.NetworkInformation namespace is of type TimeSpan which is a struct and not int.
Is this issue related to boxing and unboxing timeout?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants