Comments (10)
[Spuriga@2015/07/08]
Hello!
Could you help me, when this problem will be checked?
Thanks in advance!
from sharpvectors.
[SelormeyPaul@2015/07/09]
For a library, there is little to do. If you finish with the conversion in your application, try the following to force the clean by the .NET runtime:
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
from sharpvectors.
[UnknownUser@2015/07/13]
from sharpvectors.
[Spuriga@2015/07/13]
Hello!
I have tried it, but not success! :(
When my code is starting it use 3Mb-s of memory, and when it is finished it use 45Mb-s. I have tried it in a cycle, doing the same 10 times, and the memory increased to 450Mb-s.
In the attachement, you can find the "Csongrad_megye.svg" file. Of course I have many map file with the same situation, not this is the only one.
static void Main(string[] args)
{
byte[] svgByteArray = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Csongrad_megye.svg"));
DrawingGroup dg;
using (var stream = new MemoryStream(svgByteArray))
{
using (FileSvgReader fr = new FileSvgReader(null))
{
dg = fr.Read(stream);
}
}
dg = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Console.WriteLine("Ready!");
Console.ReadLine();
}
from sharpvectors.
[SelormeyPaul@2015/07/13]
Without testing, I could see the code you submitted is useless. How are you expecting the svgByteArray you created to go away? Why do you even need the byte array if you can directly read the file?
static void Main(string[] args)
{
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Csongrad_megye.svg");
DrawingGroup dg;
using (FileSvgReader fr = new FileSvgReader(null))
{
dg = fr.Read(filePath);
}
dg = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Console.WriteLine("Ready!");
Console.ReadLine();
}
from sharpvectors.
[Spuriga@2015/07/13]
In my application the file comes out from a WCF channel in byte array. But ok, there is no problem, with your code the situation is the same. :(
from sharpvectors.
[SelormeyPaul@2015/07/16]
Hello,
There is no memory leak and nothing to fix. You simply do not control .NET memory management and that will not change. If you want a C/C++ release of memory, the closest you can get is run your conversions in a separate domain and if you done, you release the domain to release the resources associated with that domain.
NOTE: I am, therefore, closing this issue.
using System;
using System.Windows.Media;
using System.IO;
using SharpVectors.Converters;
using System.Reflection;
namespace TestConsole
{
class Program
{
// Because this class is derived from MarshalByRefObject, a proxy
// to a MarshalByRefSvgConverter object can be returned across an AppDomain
// boundary.
public sealed class MarshalByRefSvgConverter : MarshalByRefObject
{
// Call this method via a proxy.
public void RunTest(string filePath)
{
DrawingGroup dg;
using (FileSvgReader fr = new FileSvgReader(null))
{
dg = fr.Read(filePath);
}
dg = null;
Console.WriteLine("Stage 2: " + GC.GetTotalMemory(true));
}
}
private static void RunTest(String filePath)
{
DrawingGroup dg;
using (FileSvgReader fr = new FileSvgReader(null))
{
dg = fr.Read(filePath);
}
dg = null;
Console.WriteLine("Stage 2: " + GC.GetTotalMemory(true));
GC.Collect(0, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
GC.Collect(0, GCCollectionMode.Forced);
}
static void Main(string[] args)
{
String filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Csongrad_megye.svg");
Console.WriteLine("Stage 1: " + GC.GetTotalMemory(true));
// Program.RunTest(filePath);
// Construct and initialize settings for a second AppDomain.
AppDomainSetup domainSetup = new AppDomainSetup();
domainSetup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
domainSetup.DisallowBindingRedirects = false;
domainSetup.DisallowCodeDownload = true;
domainSetup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
// Create the second AppDomain.
AppDomain svgDomain = AppDomain.CreateDomain("SVG-Converter", null, domainSetup);
// Get and display the full name of the EXE assembly.
string exeAssembly = Assembly.GetEntryAssembly().FullName;
// Create an instance of MarshalByRefSvgConverter in the second AppDomain.
// A proxy to the object is returned.
MarshalByRefSvgConverter svgProxy = (MarshalByRefSvgConverter)svgDomain.CreateInstanceAndUnwrap(
exeAssembly, typeof(MarshalByRefSvgConverter).FullName);
// Call a method on the object via the proxy, passing the filename
for (int i = 0; i < 10; i++)
{
svgProxy.RunTest(filePath);
}
// Unload the second AppDomain. This deletes its object and
// invalidates the proxy object.
AppDomain.Unload(svgDomain);
Console.WriteLine("Stage 3: " + GC.GetTotalMemory(true));
Console.WriteLine("Ready!");
Console.ReadLine();
}
}
}
from sharpvectors.
[Spuriga@2015/07/20]
Thanks, it work preatty well!
from sharpvectors.
[UnknownUser@2016/10/14]
from sharpvectors.
Issue closed by SelormeyPaul with comment
Simple memory management will resolve the issue.
Reason closed
Fixed
from sharpvectors.
Related Issues (20)
- The opacity of property of SVG not correct. HOT 5
- Svg file is different with other browser. HOT 6
- XXE vulnerability allows exfiltration of local data HOT 4
- `AppName` case style may determine whether show svg image or not HOT 1
- SharpVectors release schedule? HOT 1
- Rendering issue with elements outside the canvas HOT 3
- Target framework issue when used in .NET 4.7.2. project HOT 3
- NOTE: Dropping Support for .NET 5
- The svg image is cropped
- Not Support the extra commas in SVG elements HOT 4
- The Svg file not render correct on .net7 windows platform.
- Release New version schedule? HOT 1
- EnsureViewboxSize of WpfDrawingSettings not work when svg has viewbox. HOT 2
- Size of drawinggroup is not correct in 1.83 HOT 9
- MIT license text may be incorrect HOT 6
- Bad text display
- Corrupted rendering of Verovio SVG output HOT 3
- ViewBox is not handled correctly HOT 3
- SVG file not render correctly on 1.8.4 HOT 3
- SVG -> XAML: Transparency HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharpvectors.