diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..f5d622ff --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cquery.cacheDirectory": "${workspaceFolder}/.vscode/cquery_cached_index/" +} \ No newline at end of file diff --git a/cpp/RowGroupMetaData.cpp b/cpp/RowGroupMetaData.cpp index e8a3a2b3..966caa44 100644 --- a/cpp/RowGroupMetaData.cpp +++ b/cpp/RowGroupMetaData.cpp @@ -8,6 +8,11 @@ using namespace parquet; extern "C" { + PARQUETSHARP_EXPORT void RowGroupMetaData_Free(const RowGroupMetaData* row_group_meta_data) + { + delete row_group_meta_data; + } + PARQUETSHARP_EXPORT ExceptionInfo* RowGroupMetaData_Get_Column_Chunk_Meta_Data(const RowGroupMetaData* row_group_meta_data, int i, ColumnChunkMetaData** column_chunk_meta_data) { TRYCATCH(*column_chunk_meta_data = row_group_meta_data->ColumnChunk(i).release();) diff --git a/cpp/SchemaDescriptor.cpp b/cpp/SchemaDescriptor.cpp index ab9626b7..c2457dd6 100644 --- a/cpp/SchemaDescriptor.cpp +++ b/cpp/SchemaDescriptor.cpp @@ -8,6 +8,11 @@ using namespace parquet; extern "C" { + PARQUETSHARP_EXPORT void SchemaDescriptor_Free(const SchemaDescriptor* descriptor) + { + delete descriptor; + } + PARQUETSHARP_EXPORT ExceptionInfo* SchemaDescriptor_Column(const SchemaDescriptor* descriptor, int i, const ColumnDescriptor** column_descriptor) { TRYCATCH(*column_descriptor = descriptor->Column(i);) diff --git a/csharp/RowGroupMetaData.cs b/csharp/RowGroupMetaData.cs index 48c1936e..3bb04d87 100644 --- a/csharp/RowGroupMetaData.cs +++ b/csharp/RowGroupMetaData.cs @@ -3,11 +3,17 @@ namespace ParquetSharp { - public sealed class RowGroupMetaData + public sealed class RowGroupMetaData : IDisposable { internal RowGroupMetaData(IntPtr handle) { - _handle = handle; + _handle = new ParquetHandle(handle, RowGroupMetaData_Free); + } + + public void Dispose() + { + _schema?.Dispose(); + _handle.Dispose(); } public int NumColumns => ExceptionInfo.Return(_handle, RowGroupMetaData_Num_Columns); @@ -35,7 +41,10 @@ public ColumnChunkMetaData GetColumnChunkMetaData(int i) [DllImport(ParquetDll.Name)] private static extern IntPtr RowGroupMetaData_Total_Byte_Size(IntPtr rowGroupMetaData, out long totalByteSize); - private readonly IntPtr _handle; + [DllImport(ParquetDll.Name)] + private static extern void RowGroupMetaData_Free(IntPtr rowGroupMetaData); + + private readonly ParquetHandle _handle; private SchemaDescriptor? _schema; } } diff --git a/csharp/RowGroupReader.cs b/csharp/RowGroupReader.cs index 9e6590cc..67671898 100644 --- a/csharp/RowGroupReader.cs +++ b/csharp/RowGroupReader.cs @@ -13,6 +13,7 @@ internal RowGroupReader(IntPtr handle, ParquetFileReader parquetFileReader) public void Dispose() { + _metaData?.Dispose(); _handle.Dispose(); } diff --git a/csharp/SchemaDescriptor.cs b/csharp/SchemaDescriptor.cs index aeab3ea1..18b3d9d4 100644 --- a/csharp/SchemaDescriptor.cs +++ b/csharp/SchemaDescriptor.cs @@ -4,11 +4,16 @@ namespace ParquetSharp { - public sealed class SchemaDescriptor + public sealed class SchemaDescriptor : IDisposable { internal SchemaDescriptor(IntPtr schemaDescriptorHandle) { - _handle = schemaDescriptorHandle; + _handle = new ParquetHandle(schemaDescriptorHandle, SchemaDescriptor_Free); + } + + public void Dispose() + { + _handle.Dispose(); } public GroupNode GroupNode => (GroupNode) (Node.Create(ExceptionInfo.Return(_handle, SchemaDescriptor_Group_Node)) ?? throw new InvalidOperationException()); @@ -38,6 +43,9 @@ public Node ColumnRoot(int i) return Node.Create(ExceptionInfo.Return(_handle, i, SchemaDescriptor_Get_Column_Root)) ?? throw new InvalidOperationException(); } + [DllImport(ParquetDll.Name)] + private static extern void SchemaDescriptor_Free(IntPtr descriptor); + [DllImport(ParquetDll.Name)] private static extern IntPtr SchemaDescriptor_Column(IntPtr descriptor, int i, out IntPtr columnDescriptor); @@ -62,6 +70,6 @@ public Node ColumnRoot(int i) [DllImport(ParquetDll.Name)] private static extern IntPtr SchemaDescriptor_Schema_Root(IntPtr descriptor, out IntPtr schemaRoot); - private readonly IntPtr _handle; + private readonly ParquetHandle _handle; } }