Re: Loading Packages in a loop
- To: mathgroup at smc.vnet.net
- Subject: [mg84448] Re: Loading Packages in a loop
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Tue, 25 Dec 2007 06:24:15 -0500 (EST)
- References: <fknvm0$6cq$1@smc.vnet.net>
Hi,
and change your loop to
<< CleanSlate.m;
Do[
$HistoryLength = 0; (* some other things to save memory
*)
Unprotect[In, Out]; (* some other things to save memory
*)
Clear[In, Out]; (* some other things to save memory
*)
Protect[In, Out]; (* some other things to save memory
*)
Get["myPackage`"];(* reload my package *)
PackageFunktion[]; (* call my function *)
CleanSlateExcept["Global`"], (* clean my context *)
{i,n}
];
does not help ?
Or
<< CleanSlate.m;
Needs["myPackage`"];
Do[
$HistoryLength = 0; (* some other things to save memory
*)
Unprotect[In, Out]; (* some other things to save memory
*)
Clear[In, Out]; (* some other things to save memory
*)
Protect[In, Out]; (* some other things to save memory
*)
DeclarePackage[""myPackage`","PackageFunktion"];
PackageFunktion[]; (* call my function *)
CleanSlateExcept["Global`"], (* clean my context *)
(* reload my package *)
{i,n}
];
??
Regards
Jens
Matthias Gottschalk wrote:
> I do heavy calculations repeatedly in a loop using
> Mathematica 6.0.1.0
> For this I use a package which I load.
> For each pass in the loop the Kernel memory requirements
> increases my 50 to 100 MB. Because of this the
> calculations fail after several passes through the loop.
> I came across the CleanSlate package which in principal
> does what I want. It works and frees the memory.
>
> But I can use CleanSlate only in linear code. In any block
> (loop or blocks with labels and gotos) my calculations
> fail because I can not reload the package successfully.
> The call to CleanSlateExcept[Global`] naturally kills the
> package but I can not reload the package from inside the
> loop. The call to Needs[mypackage`] runs but my functions
> are not accessible.
>
> My code looks like this:
>
> << CleanSlate.m;
> Needs["myPackage`"];
>
> Do[
> $HistoryLength = 0; (* some other things to save memory
> *)
> Unprotect[In, Out]; (* some other things to save memory
> *)
> Clear[In, Out]; (* some other things to save memory
> *)
> Protect[In, Out]; (* some other things to save memory
> *)
> PackageFunktion[]; (* call my function *)
> CleanSlateExcept["Global`"]; (* clean my context *)
> Needs["myPackage`"], (* reload my package *)
> {i,n}
> ];
>
> The first run through the loops works, the second fails in
> the respect that the PackageFunktion[] is nor more found
> by the code.
>
> I assume that this is some Context problem.
>
> An other version of my code:
>
> << CleanSlate.m;
>
> Do[
>
> Needs["myPackage`"]; (* load my package inside the loop
> *)
>
> $HistoryLength = 0;
> Unprotect[In, Out];
> Clear[In, Out];
> Protect[In, Out];
> PackageFunktion[];
> CleanSlateExcept["Global`"],
> {i,n}
> ];
>
> in which I call the package from within the loop produces
> the following error message and no function can be called:
>
> PackageFunktion::shdw: "Symbol PackageFunktion appears in
> multiple contexts {myPackage`,Global`} definitions in
> context myPackage` may shadow or be shadowed by other
> definitions."
>
> Has somebody some an idea how I can call a package from
> within a loop?
> Can I avoid the "memory leak" of the Kernel by other
> means?
>
> Matthias
>
>
>
>