Delete uiprogress object at the end of startup function

8 views (last 30 days)
It seems that MATLAB is not deleting the uiprogress object variable when startup function in App Designer apps ends execution.
  • Does it behave differently for some local variables? I do now delete or close (pBar), but why bother when it is local variable?
function startupFcn(app)
pBar = Utility.showIndeterminateBar(app.UIFigure);
%... Still runs....
I tested a separate app, and it the correct behaviour operated but not with actual. Though I have tested it with above code, removed the Utility function so that you can test...though there is nothing...
Tested with onCleanup, the result is the same...I can conclude that this has to do with MATLAB not clearing the startupFcn on time/immediately...The question would be; is there anything that can be done to prevent this?
function onCleanUpTask = showIndeterminateBar(uifigObj)
uiprogbar = uiprogressdlg(uifigObj,'Title','Please Wait...',"Indeterminate","on");
onCleanUpTask = onCleanup(@()delete(uiprogbar));
For your full knowledge I do have:
app.onCleanupArray{1} = onCleanup(@()cleanUpTasks(ParamNumberIn));
ParamNumberIn is a param variable local to startupFcn which will be deleted when the UIFigure is deleted. Which maybe the cause that MATLAB is saving the WORKSPACE for that function because this referenced local variable?
Bereketab Gulai
Bereketab Gulai on 14 Apr 2020
I meant that
From my project was a cover function. It just returns uiprogressdlg object and I tested it with the example I have attached it works fine.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 14 Apr 2020
The uiprogressdlg outputs a handle to the progress bar. To delete the bar,
d = uiprogressdlg(h);
to reset it to 0,
d.Value = 0;
If it works when you use the uiprogressbar directly but it doesn't work when you use your wrapper function, my guess is that you're not providing the correct handle to the uiprogressbar in the output.
When you try to delete it, is there an error?
If the problem persists, please provide the entire wrapper function so we can see what's going on and share any error messages in their entirety.
Bereketab Gulai
Bereketab Gulai on 16 Apr 2020
Hi Adam,
Thank you for the comment.
  1. My project is bigger than one uifigure.
  2. There is no point in storing the uiprogressdlg object, since it needs to be deleted and recreated in each use. It cannot be stored as constant or private variable because a running uifigure is required.
  3. To meet those conditions, it can be put in a wrapper function and called whenever needed providing the running uifigure handle. This solution works perfectly, the only problem of my discussion was that "the lack of imporance of doing delete(pBar) when the pBar is local to the function thus should be deleted the end of the function.".
To conclude, the problem is with that the whole workspace for that function is saved because other variables are referenced. This discussion should probably be moved to "MATLAB support/bug centre", because this rule (Object Lifecycle), I think is not meet for this PARTICULAR variable (pBar) ("No longer referenced anywhere").

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by