Kem, Bob, & Walter.
thank you for your responses 
The files I am working with are medical images in which are stored as DICOM. With DICOM objects (for those not familiar), is a standard format in which can be used to store images, encapsulated reports, structure reports, etc…
A medical image DICOM object is has two parts:
-
DICOM Header - This is the meta data about the image which you can store just about anything too. Most common information stored here is Patient, Study, Series, SOP level information. There is also information pertaining to how a DICOM viewer should display the image.
-
The pixel data.
The cool part about DICOM files is that they are built around OOP
Since DICOM images come in all shapes and sizes, it is possible for image size to be a few megs to a few gigs depending what type of Study is being performed. With this said, the part I only care about is the DICOM header which starts at PTR 128 in the file in which I grab the first 64132 bytes of the file to parse against.
My infoUpdate Methodist goes into two parts. 1) call my dicom parser module to parse the file header 2) update the database with the results of the parse.
[code] dim db as new dbClass
dim dicom as new dicomModule.dicomClass
dim file_size, patient_mrn, patient_name, patient_dob, patient_gender, study_accession_number, study_date, study_time, study_description, study_instance_uid, series_date, series_time, series_modality, series_station, series_instance_uid, sop_instance_number, sop_instance_uid, derivation_description, sop_class_uid, sop_transfer_syntax_uid, equip_manufacture, equip_model, equip_institution, phys_referring, phys_performing, phys_reading, xmlData as String
xmlData = dicom.xml(activeFile)
patient_mrn = chr(39) +“none” + chr(39) + chr(44)
patient_name = chr(39) +“none” + chr(39) + chr(44)
patient_dob = chr(39) +“none” + chr(39) + chr(44)
patient_gender = chr(39) +“none” + chr(39) + chr(44)
study_accession_number = chr(39) +“none” + chr(39) + chr(44)
study_date = chr(39) +“none” + chr(39) + chr(44)
study_time = chr(39) +“none” + chr(39) + chr(44)
study_description = chr(39) +“none” + chr(39) + chr(44)
study_instance_uid = chr(39) +“none” + chr(39) + chr(44)
series_date = chr(39) +“none” + chr(39) + chr(44)
series_time = chr(39) +“none” + chr(39) + chr(44)
series_modality = chr(39) +“none” + chr(39) + chr(44)
series_station = chr(39) +“none” + chr(39) + chr(44)
series_instance_uid = chr(39) +“none” + chr(39) + chr(44)
sop_instance_number = chr(39) +“none” + chr(39) + chr(44)
derivation_description = chr(39) +“none” + chr(39) + chr(44)
sop_class_uid = chr(39) +“none” + chr(39) + chr(44)
sop_transfer_syntax_uid = chr(39) +“none” + chr(39) + chr(44)
equip_manufacture = chr(39) +“none” + chr(39) + chr(44)
equip_model = chr(39) +“none” + chr(39) + chr(44)
equip_institution = chr(39) +“none” + chr(39) + chr(44)
phys_referring = chr(39) +“none” + chr(39) + chr(44)
phys_performing = chr(39) +“none” + chr(39) + chr(44)
phys_reading = chr(39) +“none” + chr(39)
if activeFile = nil then
db.dbExec("exec P_PARSE_FAILED " + dbl_key)
exit
end if
if activeFile.Exists = false then
db.dbExec("exec P_PARSE_FAILED " + dbl_key)
exit
end if
if activeFile.Exists = true and activeFile.IsReadable = true and activeFile.Locked = false and activeFile.Directory = false then
file_size = chr(44) + str(activeFile.Length) + chr(44)
if dicom.checkDicom(activeFile) = true then
patient_mrn = chr(39) +dicom.xmlTag("patientID") + chr(39) + chr(44)
patient_name = chr(39) +dicom.xmlTag("patientName") + chr(39) + chr(44)
patient_dob = chr(39) +dicom.xmlTag("PatientBirthDate") + chr(39) + chr(44)
patient_gender = chr(39) +dicom.xmlTag("PatientSex") + chr(39) + chr(44)
study_accession_number = chr(39) + dicom.xmlTag("AccessionNumber") + chr(39) + chr(44)
study_date = chr(39) +dicom.xmlTag("StudyDate")+ chr(39) + chr(44)
study_time = chr(39) +dicom.xmlTag("StudyTime")+ chr(39) + chr(44)
study_description = chr(39) +dicom.xmlTag("StudyDescription")+ chr(39) + chr(44)
study_instance_uid = chr(39) +dicom.xmlTag("StudyInstanceUID")+ chr(39) + chr(44)
series_date = chr(39) +dicom.xmlTag("SeriesDate")+ chr(39) + chr(44)
series_time = chr(39) +dicom.xmlTag("SeriesTime")+ chr(39) + chr(44)
series_modality = chr(39) +dicom.xmlTag("Modality") + chr(39) + chr(44)
series_station = chr(39) +dicom.xmlTag("StationName")+ chr(39) + chr(44)
series_instance_uid = chr(39) +dicom.xmlTag("SeriesInstanceUID")+ chr(39) + chr(44)
sop_instance_number = chr(39) +dicom.xmlTag("InstanceNumber")+ chr(39) + chr(44)
sop_class_uid = chr(39) +dicom.xmlTag("SOPClassUID")+ chr(39) + chr(44)
sop_instance_uid = chr(39) +dicom.xmlTag("SOPInstanceUID")+ chr(39) + chr(44)
derivation_description = chr(39) +dicom.xmlTag("DerivationDescription")+ chr(39) + chr(44)
sop_transfer_syntax_uid = chr(39) +dicom.xmlTag("TransferSyntaxUID") + chr(39) + chr(44)
equip_manufacture = chr(39) +dicom.xmlTag("Manufacturer")+ chr(39) + chr(44)
equip_model = chr(39) +dicom.xmlTag("ManufacturersModelName") + chr(39) + chr(44)
equip_institution = chr(39) +dicom.xmlTag("InstitutionName")+ chr(39) + chr(44)
phys_referring = chr(39) +dicom.xmlTag("PerformingPhysicianName") + chr(39) + chr(44)
phys_performing = chr(39) +dicom.xmlTag("ReferringPhysicianName") + chr(39) + chr(44)
phys_reading = chr(39) +dicom.xmlTag("NameOfPhysicianReadingStudy") + chr(39)
end if
else
file_size = “0”
end if
db.dbExec ("EXEC P_PARSE_UPDATE " _
- dbl_key +file_size + patient_mrn + patient_name + patient_dob + patient_gender _
- study_accession_number + study_date + study_time + study_description + study_instance_uid _
- series_date + series_time + series_modality + series_station + series_instance_uid _
- sop_instance_number + sop_class_uid + sop_instance_uid + derivation_description + sop_transfer_syntax_uid _
- equip_manufacture + equip_model + equip_institution + phys_referring + phys_performing + phys_reading)
exception
db.dbExec("exec P_PARSE_FAILED " + dbl_key)[/code]
the problem I run into with troubleshooting this is… where the files are located… I am not able to installed Xojo to use profiler and the files cannot be copied for any reason.
In writing this application, my intent was for the tool to only keep in memory the active file it was work on long enough to parse and update the DB and then release it as the number of files I need to parse can be alot.
[quote=96614:@Kem Tekinay]Assigning nil or a new value directly shouldn’t matter. In fact, you shouldn’t have to think about memory management at all other than circular references. Any chance you have those?
Are you loading all the files into memory at once? I wasn’t clear from your latest description.
Also, does it stabilize at some point?
If you really want to get to the heart of it, start commenting or bypassing code starting at the inner processing and working out. When the memory stops being used at that clip, you can focus on the culprit.
[/quote]
Kem,
Thank you for your input. The whole file is not loaded in, just the first 64132 bytes. Here is how I do so:
[code]
dim bs as BinaryStream
if dicomFile.Locked = true or dicomFile.IsReadable = false then return false ’ check to see if file is readable
bs = BinaryStream.Open(dicomFile,false) ’ Read file to memory
if bs.Length > 64132 then
dicomMB = bs.read(64132)
else
dicomMB = bs.read(bs.Length)
end if
bs.Close
dicomMB = dicomMB.MidB(128, dicomMB.Size - 128)
dicomMB.LittleEndian = true
read(“TransferSyntaxUID”)
ts = vf
vf = “”
if dicomMB.StringValue(0,4) = “DICM” then ’ Check for DICM in Header
return true
else
return false
end if
exception ’ Error Handling
return false[/code]
As far as if the memory stabilizes, I have seen at other projects… yes it does, but here it does not.
you make a great point about working inward to the outer. I will start to look at this code more to see if I can find anything.