Skip to content

Commit

Permalink
Add W5 D1 program
Browse files Browse the repository at this point in the history
  • Loading branch information
cvpfus committed Oct 2, 2023
1 parent b07f2b2 commit 77ade8a
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
9 changes: 9 additions & 0 deletions FormulatrixBootcamp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HashTable", "W3 D3\HashTabl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QueueStack", "W3 D3\QueueStack\QueueStack.csproj", "{B48AD888-F0FA-4879-8F05-BB765527F212}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "W5 D1", "W5 D1", "{2A99B32E-4EA2-467B-A477-CB0844233CDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarbageCollection", "GarbageCollection\GarbageCollection.csproj", "{2739F473-20E7-4786-AC1F-2479A2E18A83}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -339,11 +343,16 @@ Global
{B48AD888-F0FA-4879-8F05-BB765527F212}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B48AD888-F0FA-4879-8F05-BB765527F212}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B48AD888-F0FA-4879-8F05-BB765527F212}.Release|Any CPU.Build.0 = Release|Any CPU
{2739F473-20E7-4786-AC1F-2479A2E18A83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2739F473-20E7-4786-AC1F-2479A2E18A83}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2739F473-20E7-4786-AC1F-2479A2E18A83}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2739F473-20E7-4786-AC1F-2479A2E18A83}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2739F473-20E7-4786-AC1F-2479A2E18A83} = {2A99B32E-4EA2-467B-A477-CB0844233CDC}
{77D0C1C7-A06B-4E05-9458-873709BD4BFD} = {44C682DF-E1C9-4394-813D-0CB989CD9262}
{AA5CB577-831E-40F5-AABD-AFF7C56F8A57} = {44C682DF-E1C9-4394-813D-0CB989CD9262}
{1A0A5FD8-8FC2-4ECA-8EB0-BAC6DF70E7BF} = {0458C07F-2B31-4DB7-97E4-315800A0B2C0}
Expand Down
46 changes: 46 additions & 0 deletions W5 D1/GarbageCollection/Car.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace GarbageCollection;

public class Car : IDisposable
{
private bool disposedValue;
private string _brandName;

public Car(string brandName)
{
_brandName = brandName;
}

public string GetBrandName()
{
return _brandName;
}

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
}

// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
disposedValue = true;
}
}

// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~Car()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }

public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
13 changes: 13 additions & 0 deletions W5 D1/GarbageCollection/Garbage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace GarbageCollection;

public class Garbage
{
public void CreateGarbage(int maxGarbage)
{
Car car;
for (int i = 0; i < maxGarbage; i++)
{
car = new("Ferrari");
}
}
}
8 changes: 8 additions & 0 deletions W5 D1/GarbageCollection/GarbageCollection.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
25 changes: 25 additions & 0 deletions W5 D1/GarbageCollection/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using GarbageCollection;
public class Program
{
static void Main()
{
// using(Car car = new("Honda"))
// {
// // TODO..
// }

// https://learn.microsoft.com/en-us/dotnet/api/system.gc?view=net-7.0
Garbage garbage = new();
Console.WriteLine("The highest generation is {0}", GC.MaxGeneration);
Console.WriteLine("Generation: {0}", GC.GetGeneration(garbage));
garbage.CreateGarbage(1000);

GC.Collect(0);
Console.WriteLine("Generation: {0}", GC.GetGeneration(garbage));

GC.Collect(1);
Console.WriteLine("Generation: {0}", GC.GetGeneration(garbage));


}
}

0 comments on commit 77ade8a

Please sign in to comment.