Unable to close or recreate a dictionary because it is already open, but it's actually not...

Error using myScript
Unable to create or open data dictionary
'C:\temp\my_dict.sldd'
because another dictionary with the same file name is already open. To create or open this dictionary, close all
open dictionaries by calling 'Simulink.data.dictionary.closeAll' and reopen.
Open file:
'C:\temp\my_dict.sldd'
However >> Simulink.data.dictionary.getOpenDictionaryPaths does not show the complained file and eventually because of that
>> Simulink.data.dictionary.closeAll('my_dict.sldd', '-discard') does not seem to have any effect or or at least does not solve the problem.
Why is the dictionary Matlab is complaining about not shown in the list of open dictionaries?
And how can I fix this?
>> Simulink.data.dictionary.closeAll('-discard') to wipe all works but is not an option because this would lead to failures in the following processes because of the dictionaries that are also closed but are still needed...
p.s. the old dictionary has already been wiped from the disk at the point of the test which also cannot be revoked or changed.

Answers (2)

To delete the Simulink data dictionary, run the following commands in the MATLAB Command Window:
clear my_dictDictObj; % Clear the dictionary object from the workspace
Simulink.data.dictionary.closeAll('my_dict.sldd','-discard');
delete('my_dict.sldd');
This ensures that "my_dict.sldd" is fully cleared from memory and a new dictionary can be created with the same name using
Simulink.data.dictionary.create('my_dict.sldd');
Hope this helps!

1 Comment

This does not work as per my initial post
a) clear my_dictDictObj; % Clear the dictionary object from the workspace
-> I do not have any (known) objects of that dictionary
b) delete('MY_dict.sldd');
-> The file was already deleted from the disk
>> delete(dict.file)
Warning: File
'C:\...\MY_dict.sldd'
not found.
dict = struct with fields:
name: 'MY_dict'
filename: 'MY_dict.sldd'
>> dict.file = fullfile(targetpath, dict.filename)
>> Simulink.data.dictionary.closeAll([dict.name '.sldd'], '-discard')
>> dicthandle = Simulink.data.dictionary.create(dict.file)
Unable to create or open data dictionary
'C:\...\MY_dict.sldd'
because another dictionary with the same file name is already open. To create or open this dictionary, close all open
dictionaries by calling 'Simulink.data.dictionary.closeAll' and reopen.
Open file:
'C:\...\MY_dict.sldd'
How do I close this zombie dictionary?

Sign in to comment.

Hi,
I encountered the exact same problem, but by removing the file from the project before deleting it and then adding the file to the project after creating it I am able to repeatedly exectute the script without problems.
Example below:
%% Relative path to the data dictionary
relative_path = "./dd.sldd";
[~,fname,fext] = fileparts(relative_path);
filename = append(fname, fext);
%% Try to close the data dictionary discarding any changes
try
Simulink.data.dictionary.closeAll(filename, '-discard');
fprintf("\nData dictionary closed...\n");
catch
fprintf("\nUnable to close data dictionary...\n");
end
%% Get the current project
proj = currentProject;
%% Try to remove the data dictionary from the project
try
removeFile(proj, relative_path);
fprintf("\nData dictionary removed from project...\n");
catch
fprintf("\nUnable to remove data dictionary from project...\n");
end
%% Try to delete the data dictionary
warning('error', 'MATLAB:DELETE:FileNotFound');
try
delete(relative_path);
fprintf("\nData dictionary deleted...\n");
catch
fprintf("\nUnable to delete data dictionary...\n");
end
%% Try to recreate the data dictionary
try
Simulink.data.dictionary.create(relative_path);
fprintf("\nData dictionary created...\n")
catch
fprintf("\nUnable to create data dictionary...\n");
end
%% Try to add the data dictionary to the project
try
addFile(proj, relative_path);
fprintf("\nData dictionary added to project...\n");
catch
fprintf("\nUnable to add data dictionary to project...\n");
end

1 Comment

Thanks for this hint.
In addition make sure that there is no filehandle floationg around -> fopen() on that file.
Maybe someone from mathworks can tell if there is a way to discover any filehandles from fopen() without corresponding fclose() if the return value from fopen() is no longer available.

Sign in to comment.

Products

Release

R2022b

Tags

Asked:

on 6 Jun 2025

Edited:

on 23 Feb 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!