← Back to archive
Programming Notes

SwissEphNet

历法

In order to try developing on Windows and running on Linux, I adopted ASP.NET Core. However, while using SwissEphNet, I discovered a serious problem. SwissEphNet reads files by invoking an event, which returns a file stream; that stream is then returned to a wrapping CFile object, which in turn returns it to another object. Worse still, through layers of iteration the design becomes a complete mess: somewhere the stream is never Disposed. Because resources are not released, concurrent multi-threaded access reports that the file is already locked by another process.
 

Since its calling code is simply a shambles and cannot be modified from within, a clever workaround was used: each time a CFILE object is created, register it in a dictionary along with the current stream; when the same file is accessed again, look up that file's stream, Dispose it, and recreate the CFile object. This temporarily solved the problem.

The suspicion is that it is an issue with the memory reclamation mechanism: because there are too many wrapping references, even after Dispose is called in the code, there may still be tangled references that prevent the pointer from becoming null, so the stream cannot be released.

Written by Master Sanfu on July 6, 2016. Please credit the source if you share.

Translation Notice: This English version was translated with AI assistance. Specialized, historical, religious, or culturally sensitive terms may contain nuances, inaccuracies, or debatable wording. In case of ambiguity or discrepancy, the original Chinese text shall prevail.