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

Memory Tests #12

Open
Grauenwolf opened this issue Jun 2, 2021 · 0 comments
Open

Memory Tests #12

Grauenwolf opened this issue Jun 2, 2021 · 0 comments

Comments

@Grauenwolf
Copy link
Owner

foreach (var constructor in Class.Constructors.Where(c => c.IsCreatable)) 
{ 
	<text>
	
    @Tag("Memory")
	@TestAttribute
    public void @(Test.ClassName + "_Memory_" + constructor.SafeName)()
	{

        Func<WeakReference> ctr = () =>
        {
		    try
		    {
			    return new WeakReference( @constructor.GetConstructorCode() );
		    }
		    catch (ArgumentException)
		    {
                return null;
		    }
        };

        var wr = ctr();
        if (wr == null) 
            return; //unable to create object, test aborted
		
        GC.Collect();
		GC.WaitForPendingFinalizers();
		GC.Collect();

		//verify the object was collected
		Assert.IsFalse(wr.IsAlive);		
	}
			
	</text>	
}	
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant